Skip to content

decompress: accept skippable frames with Frame_Size >= 0xFFFFFFF8 - #4966

Open
ceedot-rock wants to merge 1 commit into
meta:devfrom
ceedot-rock:fix-skippable-frame-size-limit
Open

ceedot-rock wants to merge 1 commit into
meta:devfrom
ceedot-rock:fix-skippable-frame-size-limit

Conversation

@ceedot-rock

Copy link
Copy Markdown

Fixes #4882.

readSkippableFrameSize() rejects a skippable frame when Frame_Size + 8 overflows a 32-bit value. The format allows User_Data up to 0xFFFFFFFF bytes, and the function computes the total in size_t right after that check. So on 64-bit builds the one-shot functions refuse frames with Frame_Size 0xFFFFFFF8 to 0xFFFFFFFF, while ZSTD_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 expects srcSize_wrong, because the frame is valid but cut short. On 32-bit it expects frameParameter_unsupported, the same as before.

Before / after

Using the 4 GiB frame from the issue (Frame_Size = 0xFFFFFFF8), on 64-bit Linux:

dev this PR
ZSTD_findFrameCompressedSize Unsupported frame parameter 4294967296
ZSTD_decompress Unsupported frame parameter 0 bytes
ZSTD_findDecompressedSize ZSTD_CONTENTSIZE_ERROR 0
ZSTD_decompressBound ZSTD_CONTENTSIZE_ERROR ok
ZSTD_decompressStream ok, reads whole frame ok, reads whole frame (unchanged)

New 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: pass
  • make -C tests zstreamtest && ./zstreamtest -i0: pass

I 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.

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.
@meta-cla meta-cla Bot added the CLA Signed label Nov 14, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

One-shot decoding refuses some skippable frames

1 participant