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


##########
src/test/java/org/apache/commons/compress/archivers/zip/ZipFileIgnoringLocalFileHeaderTest.java:
##########
@@ -55,7 +55,11 @@ public void testZipUnarchive() throws Exception {
         try (final ZipFile zf = openZipWithoutLFH("bla.zip")) {
             for (final Enumeration<ZipArchiveEntry> e = zf.getEntries(); 
e.hasMoreElements(); ) {
                 final ZipArchiveEntry entry = e.nextElement();
-                try (final OutputStream out = Files.newOutputStream(new 
File(dir, entry.getName()).toPath())) {
+                final File zipEntryFile = new File(dir, entry.getName());
+                if 
(!zipEntryFile.toPath().normalize().startsWith(dir.toPath())) {
+                    throw new RuntimeException("Bad zip entry");

Review Comment:
   Throwing a RE is an anti pattern AFIK, IllegalStateException or 
IllegalArgumentException would be better IMO.



##########
src/test/java/org/apache/commons/compress/archivers/JarTestCase.java:
##########
@@ -61,6 +61,9 @@ public void testJarUnarchive() throws Exception {
 
         ZipArchiveEntry entry = (ZipArchiveEntry)in.getNextEntry();
         File o = new File(dir, entry.getName());
+        if (!o.toPath().normalize().startsWith(dir.toPath().normalize())) {
+            throw new RuntimeException("Bad zip entry");

Review Comment:
   Don't throw RuntimeException, it's an anti-pattern; one of ISE or IAE is 
likely better depending on what's at fault.



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