Repository navigation
gh-160001: Honor the zdict of zlib._ZlibDecompressor on zlib-wrapped streams - #161365
Open
compiler-segfault wants to merge 1 commit into
Open
compiler-segfault wants to merge 1 commit into
compiler-segfault wants to merge 1 commit into
Conversation
… streams _ZlibDecompressor only installed its dictionary in the constructor, which covers raw deflate (wbits < 0). For a zlib-wrapped stream zlib reports Z_NEED_DICT from inflate() once it has read the header, and decompress_buf() treated that as an error path that never set an exception, so the method returned NULL and the caller got a SystemError. Install the dictionary from the decompression loop when one was supplied, and raise zlib.error when the stream requires a dictionary that was never given, matching what zlib.Decompress and zlib.decompressobj do for the same input.
compiler-segfault
force-pushed
the
fix/zlib-decompressor-zdict
branch
from
November 4, 2026 23:42
be1f5d6 to
30b2efc
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
zlib._ZlibDecompressor(zdict=...)only installs its dictionary in theconstructor, and the constructor only does that for raw deflate (
wbits < 0).For a zlib-wrapped stream zlib reports
Z_NEED_DICTfrominflate()after ithas read the header, and
decompress_buf()handled that return code byjumping to
errorwithout setting an exception. The method therefore returnedNULL with no exception set:
This applies the dictionary from the decompression loop when one was supplied,
and raises
zlib.errorwhen the stream asks for a dictionary the caller neverprovided -- which is what
zlib.Decompressandzlib.decompressobjalreadydo for the same input.
The error path also covers the FDICT-only trigger from the comments: an 8-byte
zlib header with the FDICT flag set used to raise
SystemError(and trip thefatal assertion in
ceval.con a debug build) even when nozdictwas passed,because
self->zdict == NULLwas not distinguished from a dictionary thatstill has to be installed.
Tests added to
Lib/test/test_zlib.py:testDecompressZdictWrappedandtestDecompressZdictWrappedChunks: thezdictis honored for zlib-wrapped streams, including input fed three bytesat a time so the
Z_NEED_DICTreturn happens on a later call than the first.testDecompressZdictRaw: raw deflate continues to work.testDecompressFdictHeaderWithoutZdict: the FDICT header without azdictraises
zlib.errorinstead ofSystemError../python -m test test_zlibpasses. With the C change reverted,testDecompressZdictWrapped,testDecompressZdictWrappedChunksandtestDecompressFdictHeaderWithoutZdictfail, whiletestDecompressZdictRawstill passes.