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

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

commit 07988ea07f1eb7e008c0086a3ed80165366f6637
Author: Gary D. Gregory <garydgreg...@gmail.com>
AuthorDate: Fri May 30 09:54:08 2025 -0400

    [COMPRESS-699] ArchiveStreamFactory.detect(inputStream) ArchiveException
    for TAR regression
---
 src/changes/changes.xml                            |   1 +
 .../archivers/tar/TarArchiveInputStream.java       |  10 +++++
 .../commons/compress/DetectArchiverTest.java       |   2 +-
 .../compress/archivers/tar/Compress699Test.java    |  44 +++++++++++++++++++++
 .../icure_medical_device_dart_sdk-1.2.10.tar       | Bin 0 -> 936448 bytes
 5 files changed, 56 insertions(+), 1 deletion(-)

diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 47a4904f1..27b152a5c 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -96,6 +96,7 @@ The <action> type attribute can be add,update,fix,remove.
       <action type="fix" dev="ggregory" due-to="Gary 
Gregory">ArArchiveInputStream.getBSDLongName(String) now throws its 
EOFException with a message.</action>
       <action type="fix" dev="ggregory" due-to="Gary 
Gregory">ZipEncodingHelper.getZipEncoding(*) can throw NullPointerException and 
IllegalArgumentException on bad input instead of returning a value using the 
default Charset.</action>
       <action type="fix" dev="ggregory" due-to="Gary Gregory">Javadoc 
improvements throughout.</action>
+      <action type="fix" dev="ggregory" due-to="Gary Gregory" issue= 
"COMPRESS-699">ArchiveStreamFactory.detect(inputStream) ArchiveException for 
TAR regression.</action>
       <!-- ADD -->
       <action type="add" dev="ggregory" due-to="Gary Gregory">Add 
GzipParameters.getModificationInstant().</action>
       <action type="add" dev="ggregory" due-to="Gary Gregory">Add 
GzipParameters.setModificationInstant(Instant).</action>
diff --git 
a/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStream.java
 
b/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStream.java
index 7761c6362..c24c6106c 100644
--- 
a/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStream.java
+++ 
b/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStream.java
@@ -50,6 +50,11 @@
  */
 public class TarArchiveInputStream extends ArchiveInputStream<TarArchiveEntry> 
{
 
+    /**
+     * IBM AIX <a 
href=""https://www.ibm.com/docs/sv/aix/7.2.0?topic=files-tarh-file";>tar.h</a>: 
"This field is terminated with a space only."
+     */
+    private static final String VERSION_AIX = "0 ";
+
     private static final int SMALL_BUFFER_SIZE = 256;
 
     /**
@@ -72,6 +77,11 @@ public static boolean matches(final byte[] signature, final 
int length) {
                 && ArchiveUtils.matchAsciiBuffer(TarConstants.VERSION_POSIX, 
signature, versionOffset, versionLen)) {
             return true;
         }
+        // IBM AIX tar.h 
https://www.ibm.com/docs/sv/aix/7.2.0?topic=files-tarh-file : "This field is 
terminated with a space only."
+        if (ArchiveUtils.matchAsciiBuffer(TarConstants.MAGIC_POSIX, signature, 
magicOffset, magicLen)
+                && ArchiveUtils.matchAsciiBuffer(VERSION_AIX, signature, 
versionOffset, versionLen)) {
+            return true;
+        }
         if (ArchiveUtils.matchAsciiBuffer(TarConstants.MAGIC_GNU, signature, 
magicOffset, magicLen)
                 && 
(ArchiveUtils.matchAsciiBuffer(TarConstants.VERSION_GNU_SPACE, signature, 
versionOffset, versionLen)
                         || 
ArchiveUtils.matchAsciiBuffer(TarConstants.VERSION_GNU_ZERO, signature, 
versionOffset, versionLen))) {
diff --git a/src/test/java/org/apache/commons/compress/DetectArchiverTest.java 
b/src/test/java/org/apache/commons/compress/DetectArchiverTest.java
index 71c3dfff7..f6c96a000 100644
--- a/src/test/java/org/apache/commons/compress/DetectArchiverTest.java
+++ b/src/test/java/org/apache/commons/compress/DetectArchiverTest.java
@@ -177,7 +177,7 @@ public void testEmptyZipArchive() throws Exception {
      * Tests COMPRESS-644.
      */
     @Test
-    public void testIgnoreZeroByteEntryInTarDetect() {
+    public void testIcoFile() {
         assertThrows(ArchiveException.class, () -> {
             try (InputStream in = 
createBufferedInputStream("org/apache/commons/compress/COMPRESS-644/ARW05UP.ICO"))
 {
                 assertNull(ArchiveStreamFactory.detect(in));
diff --git 
a/src/test/java/org/apache/commons/compress/archivers/tar/Compress699Test.java 
b/src/test/java/org/apache/commons/compress/archivers/tar/Compress699Test.java
new file mode 100644
index 000000000..30dcd32a9
--- /dev/null
+++ 
b/src/test/java/org/apache/commons/compress/archivers/tar/Compress699Test.java
@@ -0,0 +1,44 @@
+/*
+ * 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.assertEquals;
+
+import java.io.BufferedInputStream;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+
+import org.apache.commons.compress.archivers.ArchiveStreamFactory;
+import org.junit.Test;
+
+/**
+ * Tests https://issues.apache.org/jira/browse/COMPRESS-699
+ */
+public class Compress699Test {
+
+    @Test
+    public void testTarArchive() throws Exception {
+        final Path fileToTest = 
Paths.get("src/test/resources/org/apache/commons/compress/COMPRESS-699/icure_medical_device_dart_sdk-1.2.10.tar");
+        try (BufferedInputStream fileInputStream = new 
BufferedInputStream(Files.newInputStream(fileToTest))) {
+            assertEquals("tar", ArchiveStreamFactory.detect(fileInputStream));
+        }
+    }
+}
diff --git 
a/src/test/resources/org/apache/commons/compress/COMPRESS-699/icure_medical_device_dart_sdk-1.2.10.tar
 
b/src/test/resources/org/apache/commons/compress/COMPRESS-699/icure_medical_device_dart_sdk-1.2.10.tar
new file mode 100644
index 000000000..6f5bdf789
Binary files /dev/null and 
b/src/test/resources/org/apache/commons/compress/COMPRESS-699/icure_medical_device_dart_sdk-1.2.10.tar
 differ

Reply via email to