Repository navigation
Use the buffer limit for the safe decompress(ByteBuffer, int, ByteBuffer, int) - #161
Merged
Merged
Conversation
…fer, int) With a safe decompressor, decompress(ByteBuffer src, int srcOff, ByteBuffer dest, int destOff) computed the compressed length as src.remaining() - srcOff, mixing the buffer's position with the absolute offset. Valid input failed to decompress whenever src.position() was not 0. Use src.limit() - srcOff, which matches the absolute indexing of the other ByteBuffer arguments and the fast path. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Place it after destinationBufferLimitsDecompressedLength so that it does not conflict with the short input test from #160. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
yawkat
marked this pull request as ready for review
October 15, 2026 13:22
yawkat
enabled auto-merge (squash)
October 15, 2026 13:22
dongjoon-hyun
added a commit
to apache/spark
that referenced
this pull request
Oct 28, 2026
### What changes were proposed in this pull request? This PR aims to upgrade `at.yawk.lz4:lz4-java` to 1.12.1. ### Why are the changes needed? To bring the security fix of `v1.12.1`, which was released as a security release for [GHSA-48mj-8f7c-7qfm](GHSA-48mj-8f7c-7qfm) (severity: low, availability impact only). - https://github.com/yawkat/lz4-java/releases/tag/v1.12.1 (2026-10-22) - [LZ4BlockInputStream and LZ4FrameInputStream allocate block buffers from the block header before the block data arrives](GHSA-48mj-8f7c-7qfm): the streams now grow their buffers only as block data actually arrives (yawkat/lz4-java#167). - [Throw LZ4Exception for input shorter than the length prefix](yawkat/lz4-java#160) - [Bound the compressed length of oversized LZ4 blocks](yawkat/lz4-java#162) - [Use the buffer limit for the safe decompress(ByteBuffer, int, ByteBuffer, int)](yawkat/lz4-java#161) Note that Apache Spark's `LZ4CompressionCodec` and `Statistics` read streams via `LZ4BlockInputStream`, which is one of the code paths fixed by `GHSA-48mj-8f7c-7qfm`. **Full Changelog**: yawkat/lz4-java@v1.12.0...v1.12.1 ### Does this PR introduce _any_ user-facing change? No. There is no behavior change for valid LZ4 streams. ### How was this patch tested? - Regenerated the dependency manifest with `dev/test-dependencies.sh --replace-manifest`; the only diff is the `lz4-java` line. - `build/sbt core/compile` - `build/sbt 'core/testOnly org.apache.spark.io.CompressionCodecSuite org.apache.spark.shuffle.sort.UnsafeShuffleWriterSuite org.apache.spark.FileSuite org.apache.spark.deploy.history.EventLogFileWritersSuite'` (87 tests passed) - Pass the CIs. ### Was this patch authored or co-authored using generative AI tooling? Generated-by: Claude Sonnet 5.5 Closes #59870 from dongjoon-hyun/SPARK-60628. Authored-by: Dongjoon Hyun <dongjoon@apache.org> Signed-off-by: Dongjoon Hyun <dongjoon@apache.org>
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.
With a safe decompressor,
LZ4DecompressorWithLength.decompress(ByteBuffer src, int srcOff, ByteBuffer dest, int destOff)delegated withsrcLen = src.remaining() - srcOff. That mixes the buffer's position with an absolute offset. The method uses absolute indexing and is documented to leave positions unchanged, so the result should not depend onsrc.position(), but it did. Valid data atsrcOff = 3decompressed withsrc.position() == 0. Withsrc.position() == 3, it failed withLZ4Exception: Malformed input. With larger positions, the computed length could even be negative.This change uses
src.limit() - srcOffinstead and corrects the javadoc fromsrc[srcOff:src.remaining()]tosrc[srcOff:src.limit()]. I checked the sibling methods:decompress(ByteBuffer, ByteBuffer)correctly usessrc.position()together withsrc.remaining().src.length - srcOff.srcLenexplicitly.Found by fuzzing with micronaut-fuzzing.
Behaviour change: callers that set
src.position()to something other than 0 get correct results now, where before they got a spurious failure. A call with position 0 behaves exactly as before.Test: I added
OutOfBoundsTest.byteBufferSourceOffsetIgnoresPosition. It decompresses data atsrcOff = 3with source positions 0, 1, 3 andlimit, for fast and safe decompressors and for heap and direct buffers. It also checks that positions are unchanged. Without the fix, the safe case fails withMalformed input. With the fix,OutOfBoundsTestandLZ4Testpass.This builds on #160 (short input, already merged) and merges cleanly with it.
🤖 Generated with Claude Code