Arawoof06 opened a new pull request, #1532:
URL: https://github.com/apache/arrow-java/pull/1532

   ## What's Changed
   
   `ValidateVectorDataVisitor.validateOffsetBuffer` scans the offset buffer 
from position 1 and uses `offsets[0]` only to seed `prevValue`, so the first 
offset is never checked for being non-negative. `validateLargeOffsetBuffer` has 
the same gap. A negative first offset leaves the remaining offsets 
non-decreasing and the last offset inside the data buffer, which is all 
`ValidateVectorBufferVisitor` compares, so `ValueVectorUtility.validateFull` 
accepts the vector. That covers `VarCharVector`/`VarBinaryVector`, their large 
variants and `ListVector`/`LargeListVector`, which take their offsets verbatim 
from IPC input, and `validateFull` is what 
`ArrowReader.setValidateBatches(true)` runs on an untrusted stream. Arrow C++ 
`ValidateOffsets` rejects a negative first offset.
   
   A `VarBinaryVector` holding `aaa`, `bbb` with `offsets[0]` set to -8 passes 
`validateFull` today, and reading it then goes below the data buffer:
   
   ```
   validateFull PASSED on offsets[0] = -8
   get(0) threw java.lang.IndexOutOfBoundsException: index: -8, length: 11 
(expected: range(0, 8))
   ```
   
   With `arrow.enable_unsafe_memory_access=true` no bounds check is left, and 
the eight bytes planted in front of the data buffer come back as part of the 
value:
   
   ```
   get(0) -> [65, 65, 65, 65, 65, 65, 65, 65, 97, 97, 97] (len 11)
   ```
   
   Both helpers now check position 0 the way they already check the rest of the 
buffer. A vector whose first offset is 0 behaves as before. 
`testValidateNegativeFirstOffset` exercises the int and long helpers through 
`VarBinaryVector`, `LargeVarBinaryVector`, `ListVector` and `LargeListVector`, 
and fails on `main`. The `vector`, `algorithm`, `compression` and 
`adapter/jdbc` suites pass, and spotless and checkstyle are clean.
   


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