[common] Overflow-safe URI length check in VideoFrameDescriptor - #9618
Open
LuciferYang wants to merge 2 commits into
Open
[common] Overflow-safe URI length check in VideoFrameDescriptor#9618LuciferYang wants to merge 2 commits into
LuciferYang wants to merge 2 commits into
Conversation
deserialize validated the URI length with buffer.remaining() < uriLength + 3 * Long.BYTES. The addition wraps negative for a uriLength near Integer.MAX_VALUE, so a crafted payload passed the check and reached new byte[uriLength], ending in an OutOfMemoryError instead of the IllegalArgumentException every other malformed case produces. Validate by subtraction, in the same three checks BlobDescriptor already uses, one message each.
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.
Purpose
close #9617
VideoFrameDescriptor.deserializevalidated the URI length by adding first:For a
uriLengthnearInteger.MAX_VALUEthe addition wraps negative, the comparison againstbuffer.remaining()is then false, and control reachesnew byte[uriLength]. A crafted descriptor therefore ends inOutOfMemoryErrorfrom a 2GB allocation instead of theIllegalArgumentExceptionevery other malformed case here produces. The bytes can come from the query:descriptor_to_stringanddescriptor_to_presigned_urltakeBINARYarguments.The sibling
BlobDescriptor.deserialize, which dispatches here by magic number, already validates by subtraction and reports each case separately, so this takes the same three checks:buffer.remaining()is non-negative anduriLengthis known non-negative by the time the subtraction runs, so nothing here can wrap. Three longs rather than the sibling's two, since a video frame descriptor also carries the frame index.Tests
VideoFrameDescriptorTest.testRejectInvalidPayloadgains a case that serializes a valid descriptor and overwrites its URI length field withInteger.MAX_VALUE - 23, the smallest value whose old+ 24wrapped, then asserts the rejection message. Building the payload fromserialize()keeps the test off the version and magic byte layout.Against the unfixed code that case fails with
OutOfMemoryError: Java heap space, from the allocation the check was supposed to prevent.mvn -pl paimon-common -Dtest=VideoFrameDescriptorTest,BlobDescriptorTest teston JDK 8: 12 tests, 0 failures.spotless:checkandcheckstyle:checkon paimon-common are clean.