Repository navigation
Commit 22f9750
authored
MINOR: Check source range in ArrowBuf.setBytes for direct ByteBuffers (#1380)
## What's Changed
`ArrowBuf.setBytes(long index, ByteBuffer src, int srcIndex, int
length)` bounds-checks only the destination. When `src` is a direct
buffer it copies `length` bytes from `getByteBufferAddress(src) +
srcIndex` with `MemoryUtil.copyMemory`, so a source range past
`src.capacity()` (or a negative `srcIndex`) silently copies adjacent
native memory into the ArrowBuf, even with bounds checking enabled. For
example, `buf.setBytes(0, ByteBuffer.allocateDirect(8), 0, 64)`
succeeds. The heap path already rejects this through
`ByteBuffer.position/limit`, and the `byte[]` and `ArrowBuf` overloads
(and `NettyArrowBuf.setBytes(ByteBuf)`) check the source with
`isOutOfBounds`. This adds the same source check before either path, so
the `set/setSafe(int, ByteBuffer, int, int)` methods on the
variable-width vectors fail with `IndexOutOfBoundsException` instead of
reading out of bounds. Valid ranges behave as before. Added a regression
test to `TestArrowBuf`.1 parent de73e14 commit 22f9750
2 files changed
Lines changed: 17 additions & 0 deletions
File tree
- memory/memory-core/src
- main/java/org/apache/arrow/memory
- test/java/org/apache/arrow/memory
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
897 | 897 | | |
898 | 898 | | |
899 | 899 | | |
| 900 | + | |
| 901 | + | |
| 902 | + | |
| 903 | + | |
| 904 | + | |
| 905 | + | |
900 | 906 | | |
901 | 907 | | |
902 | 908 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
112 | 112 | | |
113 | 113 | | |
114 | 114 | | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
115 | 126 | | |
116 | 127 | | |
117 | 128 | | |
| |||
0 commit comments