Add checks for malformed sizes for ZIP64 files#129121
Open
alinpahontu2912 wants to merge 4 commits into
Open
Conversation
- Reject negative compressed/uncompressed sizes in IsOpenableInitialVerifications so a malformed Zip64 entry surfaces as InvalidDataException instead of ArgumentOutOfRangeException. - Tighten test catch to InvalidDataException only. - Simplify test comments to describe externally observable behavior. - Rename zip64 size locals and centralDirectoryOffset for clarity.
Contributor
|
Tagging subscribers to this area: @karelz, @dotnet/area-system-io-compression |
Contributor
There was a problem hiding this comment.
Pull request overview
This PR tightens ZIP64 parsing in System.IO.Compression by rejecting malformed ZIP64 extra-field values that can’t be represented by the library’s long-based surface area, ensuring corrupt metadata is rejected during parsing rather than surfacing as negative sizes later.
Changes:
- Validate ZIP64 uncompressed size, compressed size, and local header offset immediately when each field is read (so early-exit paths can’t skip validation).
- Add a regression test that crafts a minimal ZIP containing a ZIP64 uncompressed size of
0xFFFF_FFFF_FFFF_FFFF(interpreted as-1L) and assertsInvalidDataException.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/libraries/System.IO.Compression/src/System/IO/Compression/ZipBlocks.cs | Moves ZIP64 “too large for Int64” validation to field-read time (including compressed size and local header offset). |
| src/libraries/System.IO.Compression/tests/ZipArchive/zip_InvalidParametersAndStrangeFiles.cs | Adds a crafted ZIP regression test for a negative ZIP64 uncompressed size value. |
Comment on lines
284
to
310
| @@ -290,6 +303,10 @@ private static bool TryGetZip64BlockFromGenericExtraField(ZipGenericExtraField e | |||
| if (readLocalHeaderOffset) | |||
| { | |||
| zip64Block._localHeaderOffset = BinaryPrimitives.ReadInt64LittleEndian(data); | |||
| if (zip64Block._localHeaderOffset < 0) | |||
| { | |||
| throw new InvalidDataException(SR.FieldTooBigLocalHeaderOffset); | |||
| } | |||
| data = data.Slice(FieldLengths.LocalHeaderOffset); | |||
rzikm
approved these changes
Jun 8, 2026
This was referenced Jun 8, 2026
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.
Throw early if Zip64 metadata is malformed
Follow up PR for: #127990