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 2019/09/02 15:42:35 UTC

[commons-compress] branch COMPRESS-450 updated: COMPRESS-450 headerErrorOccurred need to be written somewhere, avoid NPE

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

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


The following commit(s) were added to refs/heads/COMPRESS-450 by this push:
     new d1a6b10  COMPRESS-450 headerErrorOccurred need to be written somewhere, avoid NPE
d1a6b10 is described below

commit d1a6b10bbe0a8d234160aa70935872525122802b
Author: Stefan Bodewig <bo...@apache.org>
AuthorDate: Mon Sep 2 17:41:53 2019 +0200

    COMPRESS-450 headerErrorOccurred need to be written somewhere, avoid NPE
---
 .../commons/compress/archivers/tar/TarArchiveInputStream.java      | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

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 d5d9ca0..4751ce5 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
@@ -286,7 +286,7 @@ public class TarArchiveInputStream extends ArchiveInputStream {
         byte[] headerBuf = getRecord();
 
         if (headerErrorOccurred) {
-            do {
+            while (headerBuf != null) {
                 try {
                     if (TarUtils.verifyCheckSum(headerBuf)) {
                         break;
@@ -295,8 +295,10 @@ public class TarArchiveInputStream extends ArchiveInputStream {
                     // next record is not a valid tar header either
                 }
                 entryOffset += recordSize;
-            } while ((headerBuf = getRecord()) != null);
+                headerBuf = getRecord();
+            }
         }
+        headerErrorOccurred = false;
 
         if (headerBuf == null) {
             /* hit EOF */
@@ -307,6 +309,7 @@ public class TarArchiveInputStream extends ArchiveInputStream {
         try {
             currEntry = new TarArchiveEntry(headerBuf, zipEncoding);
         } catch (final IllegalArgumentException e) {
+            headerErrorOccurred = true;
             throw new InvalidTarHeaderException(e);
         }