yakovsh commented on code in PR #435:
URL: https://github.com/apache/commons-compress/pull/435#discussion_r1388282217


##########
src/test/java/org/apache/commons/compress/compressors/z/ZCompressorInputStreamTest.java:
##########
@@ -68,4 +70,24 @@ public void 
testSingleByteReadConsistentlyReturnsMinusOneAtEof() throws IOExcept
         }
     }
 
+    @Test
+    public void testInvalidMaxCodeSize() throws IOException {
+        final File input = getFile("bla.tar.Z");
+        try (InputStream contentStream = Files.newInputStream(input.toPath())) 
{
+            byte[] content = IOUtils.toByteArray(contentStream);
+
+            // Test all possible maxCodeSize values, it will either process 
correctly, or throw an IOException
+            for (int maxCodeSize = Byte.MIN_VALUE; maxCodeSize <= 
Byte.MAX_VALUE; maxCodeSize++) {
+                content[2] = (byte) maxCodeSize;
+                try {
+                    final ZCompressorInputStream in = new 
ZCompressorInputStream(new ByteArrayInputStream(content), 1024*1024);
+                    IOUtils.toByteArray(in);
+                    assertEquals(-1, in.read());
+                } catch(Exception e) {
+                    assertInstanceOf(IOException.class, e);

Review Comment:
   Thank you for your patience.
   
   I re-factored this a little bit - the goal is to make sure that none of the 
possible values of maxCodeSize throw unexpected exceptions (meaning other than 
IOException). Since this happens during both reading and initialization, I am 
tested both. I wrapped an assertDoesNotThrow() around the code - please let me 
know if this makes more sense.



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