You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by bo...@apache.org on 2013/04/25 15:36:11 UTC

svn commit: r1475758 - in /commons/proper/compress/trunk/src: changes/changes.xml main/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStream.java main/java/org/apache/commons/compress/archivers/tar/TarBuffer.java

Author: bodewig
Date: Thu Apr 25 13:36:09 2013
New Revision: 1475758

URL: http://svn.apache.org/r1475758
Log:
COMPRESS-223 fix NPE in TarBuffer.tryToConsumeSecondEOFRecord - patch by Jeremy Gustie

Modified:
    commons/proper/compress/trunk/src/changes/changes.xml
    commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStream.java
    commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/tar/TarBuffer.java

Modified: commons/proper/compress/trunk/src/changes/changes.xml
URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/changes/changes.xml?rev=1475758&r1=1475757&r2=1475758&view=diff
==============================================================================
--- commons/proper/compress/trunk/src/changes/changes.xml (original)
+++ commons/proper/compress/trunk/src/changes/changes.xml Thu Apr 25 13:36:09 2013
@@ -44,6 +44,11 @@ The <action> type attribute can be add,u
   <body>
     <release version="1.6" date="not released, yet"
              description="Release 1.6">
+      <action type="fix" date="2013-04-25" issue="COMPRESS-223"
+              due-to="Jeremy Gustie">
+        TarBuffer.tryToConsumeSecondEOFRecord could throw a
+        NullPointerException
+      </action>
     </release>
     <release version="1.5" date="2013-03-14"
              description="Release 1.5">

Modified: commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStream.java
URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStream.java?rev=1475758&r1=1475757&r2=1475758&view=diff
==============================================================================
--- commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStream.java (original)
+++ commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStream.java Thu Apr 25 13:36:09 2013
@@ -311,11 +311,11 @@ public class TarArchiveInputStream exten
 
         byte[] headerBuf = buffer.readRecord();
 
-        if (headerBuf == null) {
+        if (buffer.isEOFRecord(headerBuf)) {
             hasHitEOF = true;
-        } else if (buffer.isEOFRecord(headerBuf)) {
-            hasHitEOF = true;
-            buffer.tryToConsumeSecondEOFRecord();
+            if (headerBuf != null) {
+                buffer.tryToConsumeSecondEOFRecord();
+            }
         }
 
         return hasHitEOF ? null : headerBuf;

Modified: commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/tar/TarBuffer.java
URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/tar/TarBuffer.java?rev=1475758&r1=1475757&r2=1475758&view=diff
==============================================================================
--- commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/tar/TarBuffer.java (original)
+++ commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/tar/TarBuffer.java Thu Apr 25 13:36:09 2013
@@ -153,12 +153,13 @@ class TarBuffer { // Not public, because
      * @return true if the record data is an End of Archive
      */
     public boolean isEOFRecord(byte[] record) {
-        for (int i = 0, sz = getRecordSize(); i < sz; ++i) {
-            if (record[i] != 0) {
-                return false;
+        if (record != null) {
+            for (int i = 0, sz = getRecordSize(); i < sz; ++i) {
+                if (record[i] != 0) {
+                    return false;
+                }
             }
         }
-
         return true;
     }
 
@@ -181,7 +182,7 @@ class TarBuffer { // Not public, because
     /**
      * Read a record from the input stream and return the data.
      *
-     * @return The record data.
+     * @return The record data or null if EOF has been hit.
      * @throws IOException on error
      */
     public byte[] readRecord() throws IOException {
@@ -407,12 +408,12 @@ class TarBuffer { // Not public, because
     }
 
     /**
-     * Tries to read the next record rewinding the stream if if is not a EOF record.
+     * Tries to read the next record rewinding the stream if it is not a EOF record.
      *
      * <p>This is meant to protect against cases where a tar
      * implemenation has written only one EOF record when two are
      * expected.  Actually this won't help since a non-conforming
-     * implementation likely won't fill full blocks consisting of - be
+     * implementation likely won't fill full blocks consisting of - by
      * default - ten records either so we probably have already read
      * beyond the archive anyway.</p>
      */