zerkman / zzlib

zlib-compressed file depacking library in Lua

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Lua5.1 with ZeroBrane does not work with zzlib, workaround propose

zballito opened this issue · comments

Hi,

  • Firstly thank you for the library you did.
  • Secondly, i am using Zerobrane IDE 1.90 [ZB, for concision] for development.
    My code consists to analyze files contained into a zip one,
    it works fine with zzlib for Lua5.3 and Lua5.2 interpreters provided by ZB
    it fails with Lua5.1 interpreters

Using ZB debugger, problem occurs on zzlib-bit32.lua (it is logic regarding the interpreter in use).
More specifically in the crc cross comparison at your code > if crc ~= crc32(result) <
crc coming from the zip is a positive integer while the one computed : crc32(result ) returns a negative integer in my use case, so comparaison fails logically.

In fact crc32(result) is binary identical to crc from bit 0 to 32 and differ after (due to the sign propagation that cause the negative value).

i do not know why difference occurs but i use the following hacks as a workaround (if it helps)
....
result = inflate_main(bs)
end
-- >> workaround >>
local crc_res = crc32(result)
if( crc_res<0 ) then
local bitmax32 = 4294967296
crc_res = bitmax32 + crc_res
end
if crc ~= crc_res then
-- if crc ~= crc32(result) then
-- << workaround <<
....

  • Thirdly, minor observation between zzlib-bit32.lua(line 298) and zzlib-bwo.lua(line297) about crc computation. in one case i read: (c xor crc) and 0xff while on other side i read : c xor (crc and 0xff)
    i think it is equivalent but surprising at first sight when looking for the root cause of previous problem ^^

thanks again.

Hi @zballito, and thank you for the bug report.
I just pushed a fix for the crc32 sign issue; it should now display the correct behaviour in all Lua implementations.

About the xor/and order, both are equivalent, since in variable c, only the lowest byte is nonzero. Hence performing low byte masking on crc then xor'ing with c is the same as doing crc xor c, then masking. I do not clearly remember why I changed the order of operators, but this clearly is not an issue.