minizip: fix heap-buffer-overflow in zipRemoveExtraInfoBlock - #1280
Open
nakata-app wants to merge 1 commit into
Open
minizip: fix heap-buffer-overflow in zipRemoveExtraInfoBlock#1280nakata-app wants to merge 1 commit into
nakata-app wants to merge 1 commit into
Conversation
zipRemoveExtraInfoBlock() read a 2-byte block-size field from the input buffer and used it unchecked as a memcpy length and pointer advance, with no validation against the buffer's remaining size. An attacker-controlled extra-field blob can therefore drive both the read cursor and the memcpy length past the end of the buffer. Add a bounds check before consuming each block header: bail out with ZIP_PARAMERROR if fewer than 4 bytes remain, or if the declared block size (dataSize + 4) exceeds what is left in the buffer. Verified with the reproducer from the report (ASan heap/stack-buffer-overflow before the fix, clean run after) and a regression case with two well-formed blocks confirming normal block-removal behavior is unchanged. Fixes madler#1276
|
@gvollant: ^ |
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.
Fixes #1276.
zipRemoveExtraInfoBlock()incontrib/minizip/zip.cread a 2-byteblock-size field directly from the input buffer and used it unchecked
as both a
memcpylength and a pointer-advance amount, with novalidation against the buffer's actual remaining size (
*dataLen).An attacker-controlled extra-field blob can drive the read cursor and
the
memcpylength past the end of the buffer.This adds a bounds check before each block header is consumed:
ZIP_PARAMERRORif fewer than 4 bytes remain in thebuffer for the header + size field
ZIP_PARAMERRORif the declared block size(
dataSize + 4) exceeds what is actually left in the bufferTesting
Reproducer from #1276, built with ASan/UBSan:
ZIP_PARAMERROR.(one matching the removal header, one not) still round-trips
correctly — the surviving block is copied through unmodified and
the new length is reported correctly. Normal block-removal
behavior is unchanged.