commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dam...@apache.org
Subject svn commit: r1482498 - in /commons/proper/compress/trunk/src: main/java/org/apache/commons/compress/archivers/sevenz/SevenZFile.java test/java/org/apache/commons/compress/archivers/sevenz/SevenZFileTest.java test/resources/7z-empty-mhc-off.7z
Date Tue, 14 May 2013 17:56:43 GMT
Author: damjan
Date: Tue May 14 17:56:43 2013
New Revision: 1482498

URL: http://svn.apache.org/r1482498
Log:
Don't NPE on archives of all empty files.


Added:
    commons/proper/compress/trunk/src/test/resources/7z-empty-mhc-off.7z   (with props)
Modified:
    commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/sevenz/SevenZFile.java
    commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/sevenz/SevenZFileTest.java

Modified: commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/sevenz/SevenZFile.java
URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/sevenz/SevenZFile.java?rev=1482498&r1=1482497&r2=1482498&view=diff
==============================================================================
--- commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/sevenz/SevenZFile.java
(original)
+++ commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/sevenz/SevenZFile.java
Tue May 14 17:56:43 2013
@@ -755,20 +755,22 @@ public class SevenZFile {
         final StreamMap streamMap = new StreamMap();
         
         int nextFolderPackStreamIndex = 0;
-        streamMap.folderFirstPackStreamIndex = new int[archive.folders.length];
-        for (int i = 0; i < archive.folders.length; i++) {
+        final int numFolders = (archive.folders != null) ? archive.folders.length : 0;
+        streamMap.folderFirstPackStreamIndex = new int[numFolders];
+        for (int i = 0; i < numFolders; i++) {
             streamMap.folderFirstPackStreamIndex[i] = nextFolderPackStreamIndex;
             nextFolderPackStreamIndex += archive.folders[i].packedStreams.length;
         }
         
         long nextPackStreamOffset = 0;
-        streamMap.packStreamOffsets = new long[archive.packSizes.length];
-        for (int i = 0; i < archive.packSizes.length; i++) {
+        final int numPackSizes = (archive.packSizes != null) ? archive.packSizes.length :
0;
+        streamMap.packStreamOffsets = new long[numPackSizes];
+        for (int i = 0; i < numPackSizes; i++) {
             streamMap.packStreamOffsets[i] = nextPackStreamOffset;
             nextPackStreamOffset += archive.packSizes[i]; 
         }
         
-        streamMap.folderFirstFileIndex = new int[archive.folders.length];
+        streamMap.folderFirstFileIndex = new int[numFolders];
         streamMap.fileFolderIndex = new int[archive.files.length];
         int nextFolderIndex = 0;
         int nextFolderUnpackStreamIndex = 0;

Modified: commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/sevenz/SevenZFileTest.java
URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/sevenz/SevenZFileTest.java?rev=1482498&r1=1482497&r2=1482498&view=diff
==============================================================================
--- commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/sevenz/SevenZFileTest.java
(original)
+++ commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/sevenz/SevenZFileTest.java
Tue May 14 17:56:43 2013
@@ -20,6 +20,15 @@ package org.apache.commons.compress.arch
 import org.apache.commons.compress.AbstractTestCase;
 
 public class SevenZFileTest extends AbstractTestCase {
+    public void testAllEmptyFilesArchive() throws Exception {
+        SevenZFile archive = new SevenZFile(getFile("7z-empty-mhc-off.7z"));
+        try {
+            assertNotNull(archive.getNextEntry());
+        } finally {
+            archive.close();
+        }
+    }
+    
     public void testHelloWorldHeaderCompressionOffCopy() throws Exception {
         checkHelloWorld("7z-hello-mhc-off-copy.7z");
     }

Added: commons/proper/compress/trunk/src/test/resources/7z-empty-mhc-off.7z
URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/test/resources/7z-empty-mhc-off.7z?rev=1482498&view=auto
==============================================================================
Binary file - no diff available.

Propchange: commons/proper/compress/trunk/src/test/resources/7z-empty-mhc-off.7z
------------------------------------------------------------------------------
    svn:mime-type = application/x-7z-compressed



Mime
View raw message