Copilot commented on code in PR #3860:
URL: https://github.com/apache/avro/pull/3860#discussion_r3567378836
##########
lang/csharp/src/apache/main/IO/BinaryDecoder.cs:
##########
@@ -76,6 +76,13 @@ public long ReadLong()
int shift = 7;
while ((b & 0x80) != 0)
{
+ // A 64-bit value uses at most 10 bytes (shifts 0..63); reject
an
+ // overlong varint rather than silently wrapping to a wrong
value.
+ if (shift >= 70)
+ {
+ throw new AvroException("Varint is too long");
+ }
+
b = read();
n |= (b & 0x7FUL) << shift;
shift += 7;
Review Comment:
ReadLong() now rejects varints that exceed 10 bytes, but it still accepts
some malformed 10-byte encodings where the 10th byte has more than 1
significant bit set. Because the shift is 63 on the 10th byte, `(b & 0x7F) <<
63` will silently drop bits above bit 63, producing an incorrect decoded value
rather than rejecting the input. Add a guard so when `shift == 63` the next
byte’s payload is only 0 or 1 (i.e., `(b & 0x7E) == 0`).
--
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]