Skip to content

Commit 6128da9

Browse files
committed
Refactor inflates uncompressed block parsing.
1 parent 8061b23 commit 6128da9

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

arch/INFLATE.LUA

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -162,12 +162,18 @@ function inflate(r, w, z)
162162
-- t = block type
163163
local f, t = bs.r(1), bs.r(2)
164164

165-
if t == 0 then
166-
-- uncompressed block: align, then read LEN, NLEN from byte stream
167-
local h, l, s = bs.r(4)
168-
l = h:byte(1) + h:byte(2)*256
169-
s = bs.r(l)
170-
as(s)
165+
if t == 0 then -- uncompressed block
166+
167+
-- lo = lower bits of 16-bit value
168+
-- hi = higher bits of 16-bit value
169+
-- l = length of value
170+
local lo, hi, l
171+
bs.a() -- align (disregard remaining bits)
172+
lo, hi = bs.r(8), bs.r(8) -- read length
173+
l = lo + hi * 256 -- calculate length
174+
lo, hi = bs.r(8), bs.r(8) -- read n-length
175+
if (l ~ (lo + hi * 256)) ~= 0xFFFF then error("stored block LEN/NLEN mismatch", 0) end
176+
for _ = 1, l do ab(bs.r(8)) end -- copy raw data
171177

172178
elseif t == 1 or t == 2 then
173179
local ll, dl, h, d = {}, {}

0 commit comments

Comments
 (0)