Repository navigation
Conversation
Contributor
Author
|
cc @emmatyping |
emmatyping
reviewed
Oct 28, 2026
emmatyping
left a comment
Member
There was a problem hiding this comment.
Thank you for working on this!
I think there are a few changes that should ensure this change is robust and won't break anyone:
- Currently, this will change the exception raised when trailing bytes that are not a zstd frame from
BadZipFile(on a mismatched crc/length check) toZstdError. I think if there is a ZstdError, we should probably raiseBadZipFilefrom that exception. - I'd like a few more tests to ensure this works as expected:
a. seek() across a frame boundary
b. trailing data and skippable frames
c. frames split across reads
Comment on lines
+1200
to
+1201
| # Continue with the next Zstandard frame. | ||
| data = self._decompressor.unused_data |
Member
There was a problem hiding this comment.
I think you want to check for .eof first, so we know the decompressor is on a frame boundary.
Member
There was a problem hiding this comment.
Also, since the decompressor can be monkeypatched (ref https://github.com/lpyu001/cpython/blob/2468c35c3b3375fe0745fa5b5429d47098ebb45e/Lib/test/test_zipfile/test_core.py#L4938), we should use getattr() instead of direct attribute access.
Preserve BadZipFile with the ZstdError as its cause. Cover seeking across frames, skippable frames, trailing data, split reads, and replacement decompressors.
Contributor
Author
|
Thanks for your review! I've updated the code accordingly. |
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.
Summary
Fix
zipfilereading of Zstandard-compressed archive members containing multiple concatenated frames.ZstdDecompressorintentionally stops after one frame and stores any remaining compressed input inunused_data.ZipExtFilepreviously treated the decompressor'seofstate as the end of the entire ZIP member. As a result, later frames were ignored, which could truncate the returned data or cause an incorrect CRC-32 error.Fix
When a Zstandard frame ends,
ZipExtFilenow:unused_data.ZstdDecompressorfor the next frame.unused_data, or reads more compressed data when the frame boundary falls between archive reads.Invalid Zstandard data is reported as
BadZipFile, with the originalZstdErrorpreserved as its cause.This keeps the single-frame semantics of
ZstdDecompressorunchanged and handles concatenated frames at thezipfilestreaming layer.Tests
Regression tests cover: