Repository navigation
fix: validate FlatBuffers vector bounds when decoding IPC metadata - #565
Open
INFO-studio wants to merge 1 commit into
Open
INFO-studio wants to merge 1 commit into
INFO-studio wants to merge 1 commit into
Conversation
Validate FlatBuffers table, vtable, and vector bounds before iterating over metadata vectors in Message and Footer decoding so corrupted headers throw an Error instead of looping out of bounds and exhausting memory. Closes apache#526.
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's Changed
Validates FlatBuffers table, vtable, and vector bounds before iterating over metadata vectors in IPC
MessageandFooterdecoding.Root Cause
In
flatbuffersJS, out-of-bounds reads onByteBuffersilently return0instead of throwing. When a corrupted IPC message header or footer declares a huge or negative vector length (e.g.RecordBatch.buffers,RecordBatch.nodes,RecordBatch.variadicBufferCounts,Schema.fields,Field.children,Union.typeIds,customMetadata, orFooter.dictionaries/recordBatches), the decoder loops over that invalid length allocating objects until V8 aborts withFATAL ERROR: Reached heap limit Allocation failed - JavaScript heap out of memory.Summary of Changes
src/ipc/metadata/message.ts: AddedvalidateFlatBufferVector()to bounds-check table offset, vtable bounds, vector offset, non-negative length, andlength * elementSize <= capacity - dataStart(accounting for 24-byteBufferstructs in metadata versions< V4and 16-byte structs inV4+), and guarded nullDictionaryBatch.data(). Applied across all vector decoding paths inmessage.ts.src/ipc/metadata/file.ts: Guarded nullFooter.schema()and validatedFooter.dictionariesandFooter.recordBatchesvectors inFooter.decode().test/unit/ipc/reader/corrupted-metadata-tests.ts: Added unit tests covering the corrupted dictionary batchbuffersandnodescases from tableFromIPC runs out of memory on a corrupted dictionary batch header instead of throwing #526, negative int32 lengths, corruptedSchema.fields, and corruptedFooter.recordBatches.Verification
exit code 134) on the corrupted dictionary batch payload.eslint(0 errors),tsc -p tsconfig/tsconfig.es2015.esm.json --noEmit(0 errors),jest test/unit/ipc/(19/19 suites, 2,931/2,931 tests passed).Closes #526.