jbonofre commented on PR #1422:
URL: https://github.com/apache/arrow-java/pull/1422#issuecomment-6820157484

   I pushed two commits on top of this branch to close a few related gaps I 
found while reviewing.
   
   **IPC and JSON (613aba636)**
   - Reject a negative `RecordBatch.length`. The `INT_MAX` check let it 
through, and it reached `setRowCount`.
   - Reject buffers with a negative offset or length, or that extend past the 
body, with an `IOException`. A negative length passed `ArrowBuf.slice` and made 
the `ArrowRecordBatch` constructor throw after retaining the body, so the body 
still leaked despite the new `finally`.
   - `deserializeMessageBatch(MessageChannelReader)` now uses an empty body 
when the message has none, as `ArrowStreamReader` does, instead of throwing a 
`NullPointerException` from the `finally`.
   - `JsonFileReader`: close the record batch in `read()`, and release the 
local buffers in `readFromJsonIntoVector`, when a later or nested column is 
rejected. Use `Math.addExact` for the offset buffer count.
   - Switched the JSON test helper to `@TempDir`.
   
   **C Data (d4c0d3f73)**
   - Build the `ArrowFieldNode` at the top of `doImport`, so an invalid array 
is rejected before it clears and reloads the provider's dictionary or loads 
child vectors.
   - Use `Math.toIntExact` for `n_children` and `n_buffers`.
   - Compute the offsets buffer size as a `long` (a length of 
`Integer.MAX_VALUE` overflowed to a negative capacity), and reject a negative 
capacity in `importBuffer`.
   - `Data.importVector`: close the vector on any `Throwable`, and keep the 
original exception if `close()` fails.
   
   Each fix comes with a test that fails without it.
   
   Not addressed here, possibly for a follow-up:
   - A null count of `-1` with a missing or empty validity buffer still gets 
through `loadValidityBuffer`. This predates the PR.
   - Rejecting negative sizes in the shared helpers 
(`getValidityBufferSizeFromCount`, `setValueCount`, `wrapForeignAllocation`) 
would cover every entry point at once, rather than one path at a time.
   


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