iemejia commented on code in PR #3930:
URL: https://github.com/apache/avro/pull/3930#discussion_r3737399358
##########
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:
Fixed in d0b6410. The bounded-read branch is now taken only when a new
allocation would otherwise be needed — i.e. `old == null || length >
old.capacity()` for `readBytes` (and the equivalent for `readString`). When a
reusable buffer of sufficient capacity is supplied there is no large up-front
allocation to guard against, so we fall through to the direct path and read
straight into it, preserving the reuse contract. Added a regression test
asserting the supplied buffer's backing array is reused.
(`DirectBinaryDecoder.readBytes` already had the same guard.)
--
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]