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


##########
lang/csharp/src/apache/main/IO/BinaryDecoder.cs:
##########
@@ -264,11 +264,53 @@ public void SkipFixed(int len)
         // Read p bytes into a new byte buffer
         private byte[] read(long p)
         {
+            if (p < 0)
+            {
+                throw new AvroException($"Can not read a negative number of 
bytes: {p}");
+            }
+
+            EnsureAvailableBytes(p);
             byte[] buffer = new byte[p];
             Read(buffer, 0, buffer.Length);

Review Comment:
   ReadBytes() ultimately allocates via read(long p). Even with 
EnsureAvailableBytes(p), a seekable stream can still declare (and contain) more 
than the maximum supported .NET array length; `new byte[p]` will then throw a 
runtime exception (e.g., OOM/overflow) rather than a consistent AvroException. 
Consider rejecting lengths above MaxDotNetArrayLength before allocating, 
similar to ReadString().



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