Repository navigation
decompress: accept skippable frames with Frame_Size >= 0xFFFFFFF8 - #4966
Open
ceedot-rock wants to merge 1 commit into
Open
ceedot-rock wants to merge 1 commit into
ceedot-rock wants to merge 1 commit into
Conversation
readSkippableFrameSize() rejected any skippable frame whose Frame_Size plus the 8-byte header overflowed a U32. The format allows User_Data up to 0xFFFFFFFF bytes, and the size is computed in size_t right after, so on 64-bit builds ZSTD_findFrameCompressedSize(), ZSTD_decompress(), ZSTD_findDecompressedSize(), ZSTD_decompressBound() and ZSTD_readSkippableFrame() refused frames that ZSTD_decompressStream() skips without error. Only reject the size when it doesn't fit in a size_t, which keeps the overflow protection from meta#1446 on 32-bit builds. Add a unit test in fuzzer.c. Fixes meta#4882.
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.
Fixes #4882.
readSkippableFrameSize()rejects a skippable frame whenFrame_Size + 8overflows a 32-bit value. The format allows User_Data up to 0xFFFFFFFF bytes, and the function computes the total insize_tright after that check. So on 64-bit builds the one-shot functions refuse frames with Frame_Size 0xFFFFFFF8 to 0xFFFFFFFF, whileZSTD_decompressStream()skips the same frames fine.This changes the check so it only rejects a size that doesn't fit in a
size_t. On 32-bit builds nothing changes: those sizes are still rejected, which keeps the infinite-loop protection from #1446.I added a unit test to
tests/fuzzer.c, next to the existing "-8 size" skippable test. It passes only the 8-byte header, so no large buffer is needed. On 64-bit it expectssrcSize_wrong, because the frame is valid but cut short. On 32-bit it expectsframeParameter_unsupported, the same as before.Before / after
Using the 4 GiB frame from the issue (Frame_Size = 0xFFFFFFF8), on 64-bit Linux:
ZSTD_findFrameCompressedSizeZSTD_decompressZSTD_findDecompressedSizeZSTD_decompressBoundZSTD_decompressStreamNew unit test: fails on dev (
FAILED ZSTD_getErrorCode(ZSTD_findFrameCompressedSize(...)) == expected) and passes with the fix.Testing (gcc, x86-64,
-fsanitize=address,undefined -fno-sanitize-recover=all):make -C tests fuzzer && ./fuzzer -v -i0: all unit tests pass./fuzzer -T60s: passmake -C tests zstreamtest && ./zstreamtest -i0: passI couldn't run a 32-bit build here, so I checked the 32-bit side by reasoning about the arithmetic and would appreciate CI confirming it.
I used AI tools to help find the relevant code, write the test, and run the checks. I reviewed the change myself.