Repository navigation
decompress: check content size when an empty last block ends the frame - #4885
Open
Huang-404-Q wants to merge 1 commit into
Open
Huang-404-Q wants to merge 1 commit into
Huang-404-Q wants to merge 1 commit into
Conversation
ZSTD_decompressContinue() verifies decodedSize against the frame's Frame_Content_Size only in the ZSTDds_decompressLastBlock path. An empty last block terminates the frame earlier, in ZSTDds_decodeBlockHeader, so ZSTD_decompressStream() accepted frames that decode fewer bytes than the declared content size, while ZSTD_decompress() rejected them with corruption_detected. Perform the same check when an empty last block ends the frame, and add a regression test to zstreamtest.
This branch has not been deployed
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.
ZSTD_decompressStreamaccepts a frame whose declaredFrame_Content_Sizedoes not match what it actually decoded, as long as the frame ends with an empty last block.The frame used here is 19 bytes: a single segment,
Frame_Content_Size = 1000000, then a 5-byte raw block plus an empty last raw block.The streaming path returns early when the last block is empty and never reaches
ZSTDds_decompressLastBlock, which is where the content-size check lives, so the check is skipped.Fix
Run the same check at that early return:
Test
New case in
tests/zstreamtest.c(test 85, "reject empty last block that underflows frame content size") builds that frame and asserts the streaming API rejects it.Without the change:
With it:
A 20-second
-T20srun also completes clean (631 tests).