Skip to content

fix: validate FlatBuffers vector bounds when decoding IPC metadata - #565

Open
INFO-studio wants to merge 1 commit into
apache:mainfrom
INFO-studio:fix/issue-526
Open

INFO-studio wants to merge 1 commit into
apache:mainfrom
INFO-studio:fix/issue-526

Conversation

@INFO-studio

Copy link
Copy Markdown

What's Changed

Validates FlatBuffers table, vtable, and vector bounds before iterating over metadata vectors in IPC Message and Footer decoding.

Root Cause

In flatbuffers JS, out-of-bounds reads on ByteBuffer silently return 0 instead 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, or Footer.dictionaries/recordBatches), the decoder loops over that invalid length allocating objects until V8 aborts with FATAL ERROR: Reached heap limit Allocation failed - JavaScript heap out of memory.

Summary of Changes

  • src/ipc/metadata/message.ts: Added validateFlatBufferVector() to bounds-check table offset, vtable bounds, vector offset, non-negative length, and length * elementSize <= capacity - dataStart (accounting for 24-byte Buffer structs in metadata versions < V4 and 16-byte structs in V4+), and guarded null DictionaryBatch.data(). Applied across all vector decoding paths in message.ts.
  • src/ipc/metadata/file.ts: Guarded null Footer.schema() and validated Footer.dictionaries and Footer.recordBatches vectors in Footer.decode().
  • test/unit/ipc/reader/corrupted-metadata-tests.ts: Added unit tests covering the corrupted dictionary batch buffers and nodes cases from tableFromIPC runs out of memory on a corrupted dictionary batch header instead of throwing #526, negative int32 lengths, corrupted Schema.fields, and corrupted Footer.recordBatches.

Verification

  • Before fix: reproduced V8 heap OOM (exit code 134) on the corrupted dictionary batch payload.
  • After fix: 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.

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

tableFromIPC runs out of memory on a corrupted dictionary batch header instead of throwing

1 participant