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


##########
src/main/java/org/apache/commons/compress/compressors/z/ZCompressorInputStream.java:
##########
@@ -72,6 +72,12 @@ public ZCompressorInputStream(final InputStream inputStream, 
final int memoryLim
         if (blockMode) {
             setClearCode(DEFAULT_CODE_SIZE);
         }
+        // maxCodeSize cannot be zero, otherwise initializeTables() will throw 
an IllegalArgumentException
+        // maxCodeSize shifted cannot be less than 256, otherwise the loop in 
initializeTables() will throw an ArrayIndexOutOfBoundsException
+        // maxCodeSize cannot be smaller than getCodeSize(), otherwise 
addEntry() will throw an ArrayIndexOutOfBoundsException
+        if (maxCodeSize <= 0 || (1 << maxCodeSize) < 256 || getCodeSize() > 
maxCodeSize) {
+            throw new IOException("Invalid maxCodeSize value: " + maxCodeSize);

Review Comment:
   Hello @yakovsh 
   Thank you for your update. I still don't understand the point of this 
change. Without this check, the code throws 
`java.lang.IllegalArgumentException: maxCodeSize is 0, must be bigger than 0` 
from `LZWInputStream.initializeTables(int, int)` . So why do we need this check 
instead of the one in `initializeTables()`?
   
   The test seems fine.



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