iemejia commented on code in PR #3857:
URL: https://github.com/apache/avro/pull/3857#discussion_r3567607188
##########
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:
Already addressed in commit 6bea53e54f — this line now uses
`CollectionAssert.AreEqual(payload, result)`.
--
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]