laserninja opened a new issue, #18113:
URL: https://github.com/apache/iceberg/issues/18113
### 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.
```java
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
- [x] I can contribute a fix for this bug independently
This report and its reproduction were prepared with AI assistance and
verified locally.
--
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]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]