[VL] Tighten cache-stats wire-edge bound checks#12224
Merged
yaooqinn merged 1 commit intoJun 3, 2026
Merged
Conversation
Two defensive-bound checks at the cpp JNI / JVM deserializer edges of the cache-stats wire path: 1. cpp JNI Java_..._serializeWithStats: GLUTEN_CHECK that the framed payload size fits in jsize (signed int32 / 2 GiB) before NewByteArray. Prevents NegativeArraySizeException with no actionable diagnostic when a >2 GiB framed payload is produced. 2. JVM CachedColumnarBatchKryoSerializer.deserializeStats: require numCols <= schema.length when schema is non-null. Catches the IOB-bound case (numCols > schema.length would index past schema(col) during type dispatch) with a clear cpp/JVM wire-mismatch IAE. The opposite direction (numCols < schema.length) is intentionally allowed — the public API is loose enough that callers (incl. existing unit-test fixtures) pass an EXPANDED 5-field-per-source-col schema where schema.length == numCols * 5. Test coverage: - 1 RED test for the JVM numCols > schema.length corrupt-frame case. - 1 sentinel for the loose-schema numCols < schema.length pattern used by ColumnarCachedBatchIntFamilyMarshalSuite et al. - 1 sentinel for the schema=null V1-wire backcompat path. - cpp side has no gtest (would require a >2 GiB allocation on CI runners; the bound itself is a one-liner immediately before the NewByteArray call).
zhli1142015
approved these changes
Jun 3, 2026
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 changes are proposed in this pull request?
Two defensive bound checks at the wire-edges of the cache-stats
serialization path:
cpp JNI
serializeWithStats:GLUTEN_CHECKthat the framedpayload fits in
jsize(signed int32, ~2 GiB) beforeNewByteArray. A payload in the (2 GiB, 4 GiB] window (allowed bythe inner
bytesLen <= UINT32_MAXcheck) would currently wrap toa negative
jsizeand surface asNegativeArraySizeExceptionwith no actionable diagnostic. Fail fast as
GlutenExceptionwithbyte count + limit.
JVM
deserializeStats: whenschema != null, requirenumCols <= schema.length. The>direction would IOB onschema(col)during type dispatch (a real corrupt-frame signal).The
<direction is intentionally allowed -- existing fixtureslike
ColumnarCachedBatchIntFamilyMarshalSuitepass an EXPANDED5-field-per-source-col schema where
schema.length == numCols * 5and only the first
numColsentries drive dispatch. The newguard catches corrupt frames at the wire boundary instead of
letting an undersized row propagate into a downstream
ArrayIndexOutOfBoundsException. The pre-existing0 <= numCols <= Int.MaxValue/5bound is preserved.Both fixes are defense-in-depth -- no production caller triggers
either path today. Recovery on the JVM side is via the existing
NonFatalcorrupt-frame catch inColumnarCachedBatchSerializer.serialize(no change), which falls back to legacy
serialize()for the batch.How was this patch tested?
ColumnarCachedBatchFramedBytesSuite: 3 new JVM tests coveringnumCols > schema.lengthrejection,numCols < schema.lengthloose-schema sentinel, and the
schema=nullV1-wire backcompatsentinel.
ColumnarCachedBatch*Suitefamily (9 suites, 69 tests): allpass against a fresh local
libgluten.so/libvelox.sobuiltfrom this branch. Local preflight (cpp + JVM compile + format +
lint) clean.
jsizeguard: exercising the bound wouldrequire materializing a >2 GiB framed payload, which risks OOM on
CI runners with 8-16 GiB total. The guard itself is a one-liner
immediately before
NewByteArray.Was this patch authored or co-authored using generative AI tooling?
Generated-by: Claude Opus 4.7