Copilot commented on code in PR #3930:
URL: https://github.com/apache/avro/pull/3930#discussion_r3737318269
##########
lang/java/avro/src/main/java/org/apache/avro/io/BinaryDecoder.java:
##########
@@ -321,6 +327,14 @@ public void skipString() throws IOException {
@Override
public ByteBuffer readBytes(ByteBuffer old) throws IOException {
int length = SystemLimitException.checkMaxBytesLength(readLong());
+ if (length != 0 && requiresBoundedRead(length)) {
+ // Large declared length on a non-seekable stream: read via a growing
buffer
+ // so a truncated/hostile stream fails after a bounded allocation rather
than
+ // allocating the full declared length up front. See requiresBoundedRead.
+ ByteBuffer result = ByteBuffer.wrap(readBoundedByteArray(length));
+ result.limit(length);
+ return result;
+ }
Review Comment:
BinaryDecoder.readBytes(ByteBuffer old) ignores the Decoder contract to
reuse `old` when it has sufficient capacity: the new bounded-read branch is
taken solely based on `requiresBoundedRead(length)`, so it will allocate a new
buffer even when `old != null && old.capacity() >= length` (see
Decoder.java:120-123). This is an observable behavioral regression for callers
relying on buffer reuse.
--
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]