Skip to content

Conversation

@oliver
Copy link
Contributor

@oliver oliver commented Jan 4, 2025

If a zlib stream contains a block that is larger than 32KB and contains uncompressed data (i.e. with compression_type=0), the parser fails because the len field is decoded as signed rather than as unsigned integer.

This PR should fix the problem; and it also adds some tests (for zlib in general, and for this specific problem).

The test file (usa_railroad.jpg.6.zlib) was created by running
  pigz -6 -c -z tests/files/usa_railroad.jpg > tests/files/usa_railroad.jpg.6.zlib
using pigz 2.6.
@oliver oliver changed the title Fix zlib uncompressed large block Fix zlib parsing of length for large uncompressed block Jan 4, 2025
oliver added 2 commits January 4, 2025 18:28
The test file (usa_railroad.jpg.0.zlib) was created by running
  pigz -0 -c -z tests/files/usa_railroad.jpg > tests/files/usa_railroad.jpg.0.zlib
using pigz 2.6.
- data length is stored as unsigned short (pigz actually creates blocks of
  65K length)
- when calculating the one's complement of the length, Python will turn it
  into a negative number. Use AND to make it positive (unsigned).
@oliver oliver force-pushed the fix-zlib-uncompressed-large-block branch from 3557d9f to e038afe Compare January 4, 2025 17:29
@vstinner vstinner merged commit 9e42b9d into vstinner:main Jan 6, 2025
2 checks passed
@vstinner
Copy link
Owner

vstinner commented Jan 6, 2025

Merged, thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants