INFO-studio opened a new pull request, #565:
URL: https://github.com/apache/arrow-js/pull/565

   ## 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 #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.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to