sile / libflate

A Rust implementation of DEFLATE algorithm and related formats (ZLIB, GZIP)
https://docs.rs/libflate
MIT License
180 stars 35 forks source link

UnexpectedEof encountered when decompressing data #56

Closed Herschel closed 4 years ago

Herschel commented 4 years ago

The following zlib-compressed data fails to decompress in libflate 1.0.2 with an UnexpectedEof error: data.zip (The compressed file is data.bin inside the zip file)

rustc 1.47.0 (18bf6b4f0 2020-10-07)

It successfully decompresses using flate2-rs with both the miniz-oxide and zlib backends.

sile commented 4 years ago

Thank you for reporting this issue. Investigating your file (data.bin), it turned out that the zlib data seems to have invalid footer bytes. ZLIB footer consists of 4-bytes ADER32 checksum, but data.bin only has 3 bytes for the footer, so an EOF error occurs during decompression. It's easy to ignore this wrong footer but I'm not sure it's okay to do so.

sile commented 4 years ago

I'd like to investigate this issue more when I have time.

Herschel commented 4 years ago

Thank you! Sorry I don't have more info; I didn't take time to look into the issue much.

For reference, this data comes from image data inside a Flash SWF file in the wild. If it's indeed a checksum error, perhaps at least a more accurate error should be thrown (Adler32Error or similar). The user could then try to gracefully ignore this specific error.

I'm unsure if flate2 also detects a checksum error and just silently swallows it, but no error is thrown in their case.

sile commented 4 years ago

After investigating this issue in more detail, it turned out this is a program bug rather than an input data corruption. I'm addressing this bug on #57. Thanks a lot for reporting this bug.