You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by pe...@apache.org on 2020/09/01 07:19:44 UTC

[commons-compress] branch master updated: COMPRESS-554 : throw IOExcepiton if error is met

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

peterlee 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 319a848  COMPRESS-554 : throw IOExcepiton if error is met
319a848 is described below

commit 319a848ce71953ace6977f9b2dc505f24576addc
Author: PeterAlfredLee <pe...@gmail.com>
AuthorDate: Tue Sep 1 15:16:53 2020 +0800

    COMPRESS-554 : throw IOExcepiton if error is met
    
    Throw an decleared IOException if a null entry is met when reading a global pax header instead of a runtime NPE.
---
 src/changes/changes.xml                                 |   7 ++++++-
 .../compress/archivers/tar/TarArchiveInputStream.java   |   4 ++++
 .../archivers/tar/TarArchiveInputStreamTest.java        |   9 +++++++++
 src/test/resources/COMPRESS-554.tar                     | Bin 0 -> 10842 bytes
 4 files changed, 19 insertions(+), 1 deletion(-)

diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 3a3731d..c10d9d7 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -214,9 +214,14 @@ The <action> type attribute can be add,update,fix,remove.
       </action>
       <action issue="COMPRESS-548" type="fix" date="2020-08-24"
               due-to="Maksim Zuev" dev="PeterLee">
-        Throw an exception when reading the zip extra field if the
+        Throw an IOException when reading the zip extra field if the
         length is too short.
       </action>
+      <action issue="COMPRESS-554" type="fix" date="2020-09-01"
+              due-to="Maksim Zuev" dev="PeterLee">
+        Throw an decleared IOException if a null entry is met when
+        reading a global pax header instead of a runtime NPE.
+      </action>
     </release>
     <release version="1.20" date="2020-02-08"
              description="Release 1.20 (Java 7)">
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 42aed57..62766f2 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
@@ -573,6 +573,10 @@ public class TarArchiveInputStream extends ArchiveInputStream {
     private void readGlobalPaxHeaders() throws IOException {
         globalPaxHeaders = parsePaxHeaders(this, globalSparseHeaders);
         getNextEntry(); // Get the actual file entry
+
+        if (currEntry == null) {
+            throw new IOException("Error detected parsing the pax header");
+        }
     }
 
     /**
diff --git a/src/test/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStreamTest.java b/src/test/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStreamTest.java
index 924542f..17f4728 100644
--- a/src/test/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStreamTest.java
+++ b/src/test/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStreamTest.java
@@ -460,6 +460,15 @@ public class TarArchiveInputStreamTest extends AbstractTestCase {
         }
     }
 
+    @Test(expected = IOException.class)
+    public void stCompress554() throws IOException {
+        try (FileInputStream in = new FileInputStream(getFile("./COMPRESS-554.tar"));
+             TarArchiveInputStream archive = new TarArchiveInputStream(in)) {
+            while (archive.getNextTarEntry() != null) {
+            }
+        }
+    }
+
     private TarArchiveInputStream getTestStream(final String name) {
         return new TarArchiveInputStream(
                 TarArchiveInputStreamTest.class.getResourceAsStream(name));
diff --git a/src/test/resources/COMPRESS-554.tar b/src/test/resources/COMPRESS-554.tar
new file mode 100644
index 0000000..71a6173
Binary files /dev/null and b/src/test/resources/COMPRESS-554.tar differ