Repository navigation
[Java] Check var-data string length against the buffer before allocating - #1150
Open
slachiewicz wants to merge 1 commit into
Open
slachiewicz wants to merge 1 commit into
slachiewicz wants to merge 1 commit into
Conversation
| final int headerLength = 2; | ||
| final int limit = parentMessage.limit(); | ||
| final int dataLength = (buffer.getShort(limit, BYTE_ORDER) & 0xFFFF); | ||
| if (dataLength < 0 || dataLength > buffer.capacity() - limit - headerLength) |
| final int headerLength = 2; | ||
| final int limit = parentMessage.limit(); | ||
| final int dataLength = (buffer.getShort(limit, BYTE_ORDER) & 0xFFFF); | ||
| if (dataLength < 0 || dataLength > buffer.capacity() - limit - headerLength) |
| final int headerLength = 2; | ||
| final int limit = parentMessage.limit(); | ||
| final int dataLength = (buffer.getShort(limit, BYTE_ORDER) & 0xFFFF); | ||
| if (dataLength < 0 || dataLength > buffer.capacity() - limit - headerLength) |
| final int headerLength = 2; | ||
| final int limit = parentMessage.limit(); | ||
| final int dataLength = (buffer.getShort(limit, BYTE_ORDER) & 0xFFFF); | ||
| if (dataLength < 0 || dataLength > buffer.capacity() - limit - headerLength) |
| final int headerLength = 2; | ||
| final int limit = parentMessage.limit(); | ||
| final int dataLength = (buffer.getShort(limit, BYTE_ORDER) & 0xFFFF); | ||
| if (dataLength < 0 || dataLength > buffer.capacity() - limit - headerLength) |
| final int headerLength = 2; | ||
| final int limit = parentMessage.limit(); | ||
| final int dataLength = (buffer.getShort(limit, BYTE_ORDER) & 0xFFFF); | ||
| if (dataLength < 0 || dataLength > buffer.capacity() - limit - headerLength) |
| final int headerLength = 2; | ||
| final int limit = parentMessage.limit(); | ||
| final int dataLength = (buffer.getShort(limit, BYTE_ORDER) & 0xFFFF); | ||
| if (dataLength < 0 || dataLength > buffer.capacity() - limit - headerLength) |
| final int headerLength = 2; | ||
| final int limit = parentMessage.limit(); | ||
| final int dataLength = (buffer.getShort(limit, BYTE_ORDER) & 0xFFFF); | ||
| if (dataLength < 0 || dataLength > buffer.capacity() - limit - headerLength) |
| final int headerLength = 2; | ||
| final int limit = parentMessage.limit(); | ||
| final int dataLength = (buffer.getShort(limit, BYTE_ORDER) & 0xFFFF); | ||
| if (dataLength < 0 || dataLength > buffer.capacity() - limit - headerLength) |
| final int headerLength = 2; | ||
| final int limit = parentMessage.limit(); | ||
| final int dataLength = (buffer.getShort(limit, BYTE_ORDER) & 0xFFFF); | ||
| if (dataLength < 0 || dataLength > buffer.capacity() - limit - headerLength) |
…ing. The generated String accessor must reject a length that is negative or runs past the buffer before it allocates the temporary byte[] or moves the limit; checking after the allocation lets the wire size it.
slachiewicz
force-pushed
the
java-vardata-string-length-check
branch
from
November 13, 2026 22:26
8850c0b to
c642be4
Compare
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.
The generated String accessor for var data allocated a byte[] of the wire length and advanced the limit before anything checked that length against the buffer, so a frame whose length prefix is negative or far larger than the message made the decoder allocate up to 2 GB, or fail with OutOfMemoryError, before it read past the buffer. The accessor now rejects such a length with IndexOutOfBoundsException before allocating or moving the limit. The IR codecs are regenerated with the same check.
The other var-data accessors (skip, wrap, Appendable) do not allocate and still rely on the buffer's own bounds checks.
Part of #969.
Verified: VarDataStringLengthTest fails on master (OutOfMemoryError: Requested array size exceeds VM limit) and passes here; sbe-tool checkstyle, tests and verifyJavaIrCodecsInSync pass.