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


##########
lang/csharp/src/apache/test/File/FileTests.cs:
##########
@@ -425,6 +425,112 @@ public void OpenAppendWriter_IncorrectOutStream_Throws()
             Assert.Throws(typeof(AvroRuntimeException), action);
         }
 
+        /// <summary>
+        /// A block with a very high compression ratio can expand to far more 
memory
+        /// than its compressed size; decompressing such a block must be 
rejected once
+        /// its decompressed size would exceed the configured maximum.
+        /// </summary>
+        [Test]
+        public void TestDeflateDecompressionLimit()
+        {
+            var codec = new DeflateCodec();
+            byte[] big = new byte[128 * 1024]; // 128 KiB of zeros, compresses 
tiny
+            byte[] compressed = codec.Compress(big);
+
+            var previous = 
Environment.GetEnvironmentVariable(Codec.MaxDecompressLengthEnvVar);
+            
Environment.SetEnvironmentVariable(Codec.MaxDecompressLengthEnvVar, "65536"); 
// 64 KiB
+            try
+            {
+                Assert.Throws<AvroRuntimeException>(
+                    () => codec.Decompress(compressed, compressed.Length));
+            }
+            finally
+            {
+                
Environment.SetEnvironmentVariable(Codec.MaxDecompressLengthEnvVar, previous);
+            }
+        }
+
+        [Test]
+        public void TestDeflateWithinDecompressionLimit()
+        {
+            var codec = new DeflateCodec();
+            byte[] payload = System.Text.Encoding.UTF8.GetBytes("hello world");
+            byte[] compressed = codec.Compress(payload);
+
+            var previous = 
Environment.GetEnvironmentVariable(Codec.MaxDecompressLengthEnvVar);
+            
Environment.SetEnvironmentVariable(Codec.MaxDecompressLengthEnvVar, "65536"); 
// 64 KiB
+            try
+            {
+                byte[] result = codec.Decompress(compressed, 
compressed.Length);
+                Assert.AreEqual(payload, result);
+            }

Review Comment:
   `Assert.AreEqual(payload, result)` is less explicit for byte-array 
comparisons and tends to produce less helpful failure output. Use 
`CollectionAssert.AreEqual(...)` (or an equivalent sequence comparison) to 
clearly assert element-wise equality for the decompressed payload.



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