Copilot commented on code in PR #3864:
URL: https://github.com/apache/avro/pull/3864#discussion_r3567333527


##########
lang/perl/lib/Avro/BinaryDecoder.pm:
##########
@@ -380,6 +626,12 @@ sub unsigned_varint {
     my $more;
     my $shift = 0;
     do {
+        # A 64-bit value uses at most 10 bytes (shifts 0..63); reject an 
overlong
+        # varint rather than reading an unbounded continuation chain and 
letting
+        # $shift overflow into a garbage value.
+        if ($shift >= 70) {
+            throw Avro::Schema::Error::Parse("Varint is too long");
+        }
         $reader->read(my $buf, 1);
         my $byte = ord $buf;

Review Comment:
   `unsigned_varint` doesn’t check the return value of `$reader->read(...)`. On 
EOF/short reads, `$buf` can be empty and `ord $buf` becomes 0, which can 
silently decode truncated input as a valid 0 byte (and potentially make 
higher-level decoders loop or allocate based on corrupted values). Treat a 
short/undefined read as a parse error instead of continuing.



-- 
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]

Reply via email to