Description
Zig Version
0.12.0-dev.2790+fc7dd3e28
Steps to Reproduce and Observed Behavior
Clone https://github.com/ianprime0509/zig-zlib-issue at commit 076f340acd113b73162800b43cc0add3a0141bd0
and run zig test test-new.zig
. The test fails:
Test [1/1] test.decompress... FAIL (TestUnexpectedResult)
/var/home/ian/src/zig/lib/std/testing.zig:546:14: 0x103c6cf in expect (test)
if (!ok) return error.TestUnexpectedResult;
^
/var/home/ian/src/zig/lib/test-new.zig:25:9: 0x103c961 in test.decompress (test)
0 passed; 0 skipped; 1 failed.
If the expect
call on line 25 is commented out, the test will fail with the error BadZlibHeader
.
Expected Behavior
The test should pass. The input data to the test is the concatenation of two zlib data streams: when using std.compress.zlib.decompressor
at the beginning of the concatenated stream and reading the entire decompressed content, the underlying reader should not be advanced past the end of the first zlib data stream, so that the second data stream can be decompressed starting at the end of the first one.
A successful outcome can be reproduced by checking out 7204ecc (the commit just before the new gzip changes were merged) and running zig test test-old.zig
, which is identical to test-new.zig
except it uses the old std.compress.zlib
API.
For context on where this is necessary, an entry in a Git packfile consists of a header followed by zlib-compressed data, and the header only contains the uncompressed length of the data, so it is impossible to know where the second entry in a packfile begins without reading the first entry's compressed data precisely to the end and no further. Unfortunately, this means the Git package fetching support is currently broken.
I haven't delved too deeply into the new zlib code to find out how large of a change this would be, but I think this is a reasonable constraint to make on the decompress reader API, given formats such as Git packfiles which rely on knowing exactly where the decompressed data ends.