harden: ZstdException on oversized declared size + decompression-bomb tests#35
Merged
Conversation
…ling Zstd.decompress(byte[]) reads the (untrusted) content size from the frame header to size its output. A header declaring more than Integer.MAX_VALUE bytes previously let a raw ArithmeticException escape from Math.toIntExact; it now fails with a ZstdException naming the limit and pointing to decompress(byte[], int) for bounded, untrusted-safe decoding. Adds ZstdTest.UntrustedInput documenting decompression-bomb behaviour: - decompress(byte[], maxSize) refuses a tiny frame that expands to 8 MiB, - decompress(byte[]) trusts the declared size and expands fully (so untrusted callers must pass a bound), - a hand-built frame header declaring > 2 GiB throws ZstdException, not ArithmeticException. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Adds a Security note to Zstd.decompress(byte[]) that it trusts the frame's declared content size and can be a decompression-bomb vector, steering untrusted callers to decompress(byte[], int); and notes on the bounded overload that it is the safe entry point for untrusted input. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
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.
What
Hardening for untrusted compressed input, from the security review.
(c) Oversized declared size →
ZstdExceptionZstd.decompress(byte[])sizes its output from the frame's attacker-controlled declared content size. A header claiming >Integer.MAX_VALUEbytes previously leaked a rawArithmeticExceptionfromMath.toIntExact. It now throws aZstdExceptionnaming the limit and pointing todecompress(byte[], int).(a) Decompression-bomb tests
New
ZstdTest.UntrustedInputpins the behaviour:decompress(byte[], maxSize)refuses a tiny frame that expands to 8 MiB (the safe path).decompress(byte[])trusts the declared size and expands fully — documenting that untrusted callers must pass a bound.ZstdException, notArithmeticException.Not in scope (deferred)
(b) the Javadoc security note steering untrusted callers to
maxSize— say the word and I'll add it.Verify
235 tests green, checkstyle + javadoc clean.
🤖 Generated with Claude Code