This is an automated email from the ASF dual-hosted git repository.

garydgregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-compress.git


The following commit(s) were added to refs/heads/master by this push:
     new 406dbc224 [COMPRESS-714] Internal IllegalArgumentException in ZipFile 
and TarFile creation is not caught (#754)
406dbc224 is described below

commit 406dbc224f820e3bf961268a635e006f2c14d0da
Author: Gary Gregory <[email protected]>
AuthorDate: Tue Apr 28 11:04:35 2026 -0400

    [COMPRESS-714] Internal IllegalArgumentException in ZipFile and TarFile 
creation is not caught (#754)
    
    * [COMPRESS-714] Internal IllegalArgumentException in ZipFile and TarFile
    creation is not caught
    
    * The bug fix for [COMPRESS-714] is better done in Commons IO
    
    * TEMP in PR until IO is released.
    
    * The bug fix for [COMPRESS-714] is better done in Commons IO
    
    * The bug fix for [COMPRESS-714] is better done in Commons IO
    
    * Use IOUtils.close[Quietly]()
    
    * Pick up Commons IO 2.22.0
    
    * Removing temporary Maven repository and fix tag
    
    Removed temporary repository configuration and cleaned up dependency 
closing tag.
---
 .../compress/archivers/sevenz/SevenZFile.java      |  4 +-
 .../commons/compress/archivers/tar/TarFile.java    |  5 +-
 .../commons/compress/archivers/zip/ZipFile.java    |  6 +--
 .../compress/archivers/tar/TarCompress714Test.java | 54 ++++++++++++++++++++++
 .../compress/archivers/zip/ZipCompress714Test.java | 41 ++++++++++++++++
 5 files changed, 99 insertions(+), 11 deletions(-)

diff --git 
a/src/main/java/org/apache/commons/compress/archivers/sevenz/SevenZFile.java 
b/src/main/java/org/apache/commons/compress/archivers/sevenz/SevenZFile.java
index 47c3162fb..81aaffee1 100644
--- a/src/main/java/org/apache/commons/compress/archivers/sevenz/SevenZFile.java
+++ b/src/main/java/org/apache/commons/compress/archivers/sevenz/SevenZFile.java
@@ -636,9 +636,7 @@ private SevenZFile(final Builder builder) throws 
IOException {
             archive = readHeaders(password);
             this.password = password != null ? Arrays.copyOf(password, 
password.length) : null;
         } catch (final ArithmeticException | IllegalArgumentException e) {
-            final ArchiveException archiveException = new ArchiveException(e);
-            IOUtils.close(channel, archiveException::addSuppressed);
-            throw archiveException;
+            throw IOUtils.closeQuietlySuppress(channel, new 
ArchiveException(e));
         }
     }
 
diff --git 
a/src/main/java/org/apache/commons/compress/archivers/tar/TarFile.java 
b/src/main/java/org/apache/commons/compress/archivers/tar/TarFile.java
index 1973ac07b..952c46b07 100644
--- a/src/main/java/org/apache/commons/compress/archivers/tar/TarFile.java
+++ b/src/main/java/org/apache/commons/compress/archivers/tar/TarFile.java
@@ -193,9 +193,8 @@ private TarFile(final Builder builder) throws IOException {
             while ((entry = getNextTarEntry()) != null) {
                 entries.add(entry);
             }
-        } catch (final IOException ex) {
-            IOUtils.close(archive, ex::addSuppressed);
-            throw ex;
+        } catch (final IOException e) {
+            throw IOUtils.closeQuietlySuppress(archive, e);
         }
     }
 
diff --git 
a/src/main/java/org/apache/commons/compress/archivers/zip/ZipFile.java 
b/src/main/java/org/apache/commons/compress/archivers/zip/ZipFile.java
index bc69ff106..1a7ff812e 100644
--- a/src/main/java/org/apache/commons/compress/archivers/zip/ZipFile.java
+++ b/src/main/java/org/apache/commons/compress/archivers/zip/ZipFile.java
@@ -756,12 +756,8 @@ private ZipFile(final Builder builder) throws IOException {
             }
             fillNameMap();
         } catch (final IOException e) {
-            final ArchiveException archiveException = e instanceof 
ArchiveException
-                    ? (ArchiveException) e
-                    : new ArchiveException("Error reading Zip content from " + 
builder.getName(), (Throwable) e);
             this.closed = true;
-            IOUtils.close(archive, archiveException::addSuppressed);
-            throw archiveException;
+            throw IOUtils.closeQuietlySuppress(archive, e);
         }
     }
 
diff --git 
a/src/test/java/org/apache/commons/compress/archivers/tar/TarCompress714Test.java
 
b/src/test/java/org/apache/commons/compress/archivers/tar/TarCompress714Test.java
new file mode 100644
index 000000000..edc58743b
--- /dev/null
+++ 
b/src/test/java/org/apache/commons/compress/archivers/tar/TarCompress714Test.java
@@ -0,0 +1,54 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.commons.compress.archivers.tar;
+
+import static org.junit.jupiter.api.Assertions.assertThrows;
+
+import java.io.EOFException;
+import java.io.IOException;
+
+import org.apache.commons.compress.utils.SeekableInMemoryByteChannel;
+import org.junit.jupiter.api.Test;
+
+/**
+ * Tests https://issues.apache.org/jira/browse/COMPRESS-714
+ */
+public class TarCompress714Test {
+
+    @Test
+    public void testIllegalPosition() throws IOException {
+        final byte[] data = { 46, 101, 97, 115, 97, 47, 120, -64, 72, 98, -18, 
2, 53, 101, 112, 0, 0, 115, 8, 0, 0, 0, 112, 115, 40, 1, 0, 36, 2, 108, 0, -1,
+                -1, 0, 0, 0, 74, 0, 0, 0, 0, -1, 0, 1, 67, -2, 8, 0, 0, 0, 0, 
-64, -1, -1, -34, 9, 0, -120, -120, -120, -120, -120, -120, -120, -120, -120,
+                -120, -120, -120, -120, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 0, 
0, 0, 63, 0, 0, 0, 0, 0, 0, -65, -1, -126, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
-128,
+                -1, -1, -1, -1, 0, -122, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
-128, 0, 0, 0, 0, 35, 0, 53, 0, 0, 0, 0, 0, 0, 32, 56, 0, 0, 0, 0, 0, 0, -120, 
55, 55,
+                55, 55, 55, 55, 55, 55, 55, 55, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
0, 0, 0, 0, 0, -105, 0, 0, 0, 49, 36, -1, -1, -1, -1, -1, -1, -126, 0, 0, 0, 0, 
0,
+                0, 0, 53, 0, 0, 0, -128, 0, 0, 0, 0, 16, -1, -1, -1, -1, -1, 
-1, -1, -1, -1, -1, -1, 46, 101, 97, 115, 97, 47, 120, -64, 72, 98, -18, 2, 53,
+                101, 112, 0, 0, 115, 8, 0, 0, 0, 112, 115, 40, 1, 0, 2, 108, 
0, -1, -1, 0, 0, 0, 74, 0, 0, 0, 0, -1, 0, 1, 67, -2, 8, 0, 0, 0, 0, -64, -1, 
-1,
+                -34, 9, 0, -120, -120, -120, -120, -120, -120, -120, -120, 
-120, -120, -120, -120, -120, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 0, 0, 0, 63, 
0, 0,
+                0, 0, 0, 0, -65, -1, -126, 0, 26, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
0, -128, -1, -1, -1, -1, 0, -122, 0, 0, 0, 0, 0, 0, -128, 0, 0, 0, 0, 35, 0, 
53, 0,
+                0, 0, 0, 0, 0, 32, 56, 0, 0, 0, 0, 0, 0, -120, 55, 55, 55, 55, 
55, 55, 55, 55, 55, 55, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -105, 0, 0,
+                0, 49, 36, -1, -1, -1, -1, -1, -1, -126, 0, 0, 0, 0, 0, 0, 0, 
53, 0, 0, 0, -128, 0, 0, 0, 0, 16, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 
-1,
+                -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 
-65,
+                -1, -126, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -128, -1, -1, -1, 
-1, 0, -122, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -128, 0, 0, 0, 0, 35, 0, 53, 0, 
0, 0,
+                0, 0, 0, 32, 56, 0, 0, 0, 0, 0, 0, 0 };
+        assertThrows(EOFException.class, () -> 
TarFile.builder().setChannel(new SeekableInMemoryByteChannel(data)).get());
+        assertThrows(EOFException.class, () -> 
TarFile.builder().setByteArray(data).get());
+    }
+}
diff --git 
a/src/test/java/org/apache/commons/compress/archivers/zip/ZipCompress714Test.java
 
b/src/test/java/org/apache/commons/compress/archivers/zip/ZipCompress714Test.java
new file mode 100644
index 000000000..31269941a
--- /dev/null
+++ 
b/src/test/java/org/apache/commons/compress/archivers/zip/ZipCompress714Test.java
@@ -0,0 +1,41 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   https://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.commons.compress.archivers.zip;
+
+import static org.junit.jupiter.api.Assertions.assertThrows;
+
+import java.io.EOFException;
+import java.io.IOException;
+
+import org.apache.commons.compress.utils.SeekableInMemoryByteChannel;
+import org.junit.jupiter.api.Test;
+
+/**
+ * Tests https://issues.apache.org/jira/browse/COMPRESS-714
+ */
+public class ZipCompress714Test {
+
+    @Test
+    public void testIllegalPosition() throws IOException {
+        final byte[] data = { 80, 75, 5, 6, -127, 80, 75, 5, 6, 7, -127, -127, 
-127, 80, 74, 7, 8, -127, -127, -127, -127, -127 };
+        assertThrows(EOFException.class, () -> 
ZipFile.builder().setChannel(new SeekableInMemoryByteChannel(data)).get());
+        assertThrows(EOFException.class, () -> 
ZipFile.builder().setByteArray(data).get());
+    }
+}

Reply via email to