fix(java): reject encoder push length exceeding input buffer capacity - #1523
Open
3412-cloud wants to merge 1 commit into
Open
fix(java): reject encoder push length exceeding input buffer capacity#15233412-cloud wants to merge 1 commit into
3412-cloud wants to merge 1 commit into
Conversation
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.
Summary
EncoderJNI.Wrapper.push(int length)validates onlylength >= 0. It does not validate thatlength <= inputBuffer.capacity().nativePush()storesinput_lengthwithout an upper bound and passes it asavailable_intoBrotliEncoderCompressStream, which reads*available_inbytes from the input buffer. A caller invokingnew EncoderJNI.Wrapper(1).push(PROCESS, 32)with a 1-byte input buffer causes a heap out-of-bounds read of 32 bytes.This is the same bug that was fixed in the DECODER in commit 2dc2a5f ("fix(java): reject decoder push length exceeding input buffer capacity"), which added an upper-bound check in
Wrapper.push()plus native defense-in-depth (allocation size stored in the handle). The encoder was left unfixed.Fix (mirroring the decoder fix 2dc2a5f)
EncoderJNI.Wrapper.push: rejectlength > inputBuffer.capacity()withIllegalArgumentException.EncoderHandleand reject oversizedinput_lengthinnativePush().EncoderJNITest): rejection of oversized/negative lengths and a valid round trip withlength == capacity.Verification
Before the fix, ASAN reports a heap-buffer-overflow READ of size 32 (memcpy in
RingBufferWrite, c/enc/ringbuffer.h:115 viaCopyInputToRingBuffer->BrotliEncoderCompressStream). After the fix, the same trigger raisesIllegalArgumentException: block length exceeds input buffer capacity.Reported privately to Google OSS VRP (issue 549278294); coordinated disclosure, not public.