Skip to content

DecimalVector and Decimal256Vector raw write paths do not validate the value length before writing #1417

Closed

Description

@andygrove

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:

  • setBigEndian(int, byte[]) / setBigEndianSafe(int, byte[])
  • setSafe(int, long, ArrowBuf, int length)
  • setBigEndianSafe(int, long, ArrowBuf, int length)

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.

Reproducer (little-endian host, default bounds checking):

try (DecimalVector v = new DecimalVector("d", allocator, 38, 0)) {
  v.allocateNew(64);
  for (int i = 0; i < 8; i++) {
    v.setSafe(i, BigDecimal.valueOf(i));
  }
  int last = v.getValueCapacity() - 1;
  try {
    v.setBigEndianSafe(last, new byte[17]); // throws IllegalArgumentException ...
  } catch (IllegalArgumentException expected) {
  }
  v.isNull(0); // ... but is now true: the 17th byte landed in the validity buffer
}

Version: main (67ef5ab). Platform: macOS arm64, JDK 17.

Component(s)

Vector

Activity

  1. added
    Type: bug
    on Oct 31, 2026
  2. added this to the 20.0.0 milestone on Oct 31, 2026
  3. added a commit that references this issue on Nov 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type: bug

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions