Apache Iceberg version
main (development), commit c4784768b
Query engine
Other: Java API
Please describe the bug
A valid binary partition transform throws for an input buffer with a nonzero position when the width is sufficiently large.
ByteBuffer input = ByteBuffer.wrap(new byte[] {0, 1, 2});
input.position(1);
Transforms.<ByteBuffer>truncate(Integer.MAX_VALUE)
.bind(Types.BinaryType.get()).apply(input);
Expected: preserve the remaining bytes [1, 2], because the width exceeds the remaining length.
Actual: IllegalArgumentException: newLimit < 0: (-2147483648 < 0).
The same exception occurs while computing a PartitionKey for a binary column. BinaryUtil.truncateBinaryUnsafe adds position to width before clamping to the limit, so the addition overflows.
Proposed fix: clamp width to remaining bytes before adding the position. Preserve the input state and the returned buffer's shared backing storage.
Willingness to contribute
This report and its reproduction were prepared with AI assistance and verified locally.
Apache Iceberg version
main (development), commit
c4784768bQuery engine
Other: Java API
Please describe the bug
A valid binary partition transform throws for an input buffer with a nonzero position when the width is sufficiently large.
Expected: preserve the remaining bytes
[1, 2], because the width exceeds the remaining length.Actual:
IllegalArgumentException: newLimit < 0: (-2147483648 < 0).The same exception occurs while computing a
PartitionKeyfor a binary column.BinaryUtil.truncateBinaryUnsafeadds position to width before clamping to the limit, so the addition overflows.Proposed fix: clamp width to remaining bytes before adding the position. Preserve the input state and the returned buffer's shared backing storage.
Willingness to contribute
This report and its reproduction were prepared with AI assistance and verified locally.