You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
DecimalVector and Decimal256Vector raw write paths do not validate the value length before writing #1417
Describe the bug, including details regarding any error messages, version, and platform.
DecimalVector and Decimal256Vector have three public write paths that copy directly into native memory with MemoryUtil rather than through ArrowBuf, so ArrowBuf bounds checking does not apply to them:
Each of them bounds-checks the 16- or 32-byte destination slot, but none of them validates that the value length fits in that slot before copying:
setBigEndian(int, byte[]) copies all value.length bytes on little-endian hosts and only then throws IllegalArgumentException for lengths above TYPE_WIDTH. The exception is correct but the overrun has already happened.
The two ArrowBuf variants never check length against TYPE_WIDTH at all, so an oversized length is copied past the slot with no exception.
The two ArrowBuf variants also handle length == 0 by reading the byte at start - 1 for sign extension, so a zero-length value can decode as -1 depending on the preceding byte.
Because the value buffer and validity buffer are adjacent slices of one allocation, a write of TYPE_WIDTH + 1 bytes into the last slot of a vector clears the first validity byte, which is observable with isNull(). Larger lengths write beyond the allocation. This happens with the default arrow.enable_unsafe_memory_access=false.
The same paths are reachable through the generated DecimalWriter.writeBigEndianBytesToDecimal(byte[]) and Decimal256Writer.writeBigEndianBytesToDecimal256(byte[]), which call setBigEndianSafe without a length guard.
Activity
apacheGH-1417: Validate decimal value length before raw writes in Dec…