commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bode...@apache.org
Subject svn commit: r1586935 - in /commons/proper/compress/trunk/src: changes/ main/java/org/apache/commons/compress/archivers/arj/ main/java/org/apache/commons/compress/archivers/dump/ main/java/org/apache/commons/compress/archivers/sevenz/ main/java/org/apac...
Date Sun, 13 Apr 2014 08:32:47 GMT
Author: bodewig
Date: Sun Apr 13 08:32:47 2014
New Revision: 1586935

URL: http://svn.apache.org/r1586935
Log:
COMPRESS-276 verify there is a current archive entry before reading from or writing to the
stream

Modified:
    commons/proper/compress/trunk/src/changes/changes.xml
    commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/arj/ArjArchiveInputStream.java
    commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/dump/DumpArchiveInputStream.java
    commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/sevenz/SevenZFile.java
    commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/sevenz/SevenZOutputFile.java
    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/TarArchiveOutputStream.java
    commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveOutputStream.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=1586935&r1=1586934&r2=1586935&view=diff
==============================================================================
--- commons/proper/compress/trunk/src/changes/changes.xml (original)
+++ commons/proper/compress/trunk/src/changes/changes.xml Sun Apr 13 08:32:47 2014
@@ -59,6 +59,10 @@ The <action> type attribute can be add,u
         IOUtils#skip might skip fewer bytes than requested even though
         more could be read from the stream.
       </action>
+      <action type="add" date="2014-04-13" issue="COMPRESS-276">
+        ArchiveStreams now validate there is a current entry before
+        rreading or writing entry data.
+      </action>
     </release>
     <release version="1.8" date="2014-03-12"
              description="Release 1.8">

Modified: commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/arj/ArjArchiveInputStream.java
URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/arj/ArjArchiveInputStream.java?rev=1586935&r1=1586934&r2=1586935&view=diff
==============================================================================
--- commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/arj/ArjArchiveInputStream.java
(original)
+++ commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/arj/ArjArchiveInputStream.java
Sun Apr 13 08:32:47 2014
@@ -341,6 +341,9 @@ public class ArjArchiveInputStream exten
     
     @Override
     public int read(final byte[] b, final int off, final int len) throws IOException {
+        if (currentLocalFileHeader == null) {
+            throw new IllegalStateException("No current arj entry");
+        }
         if (currentLocalFileHeader.method != LocalFileHeader.Methods.STORED) {
             throw new IOException("Unsupported compression method " + currentLocalFileHeader.method);
         }

Modified: commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/dump/DumpArchiveInputStream.java
URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/dump/DumpArchiveInputStream.java?rev=1586935&r1=1586934&r2=1586935&view=diff
==============================================================================
--- commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/dump/DumpArchiveInputStream.java
(original)
+++ commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/dump/DumpArchiveInputStream.java
Sun Apr 13 08:32:47 2014
@@ -465,6 +465,10 @@ public class DumpArchiveInputStream exte
             return -1;
         }
 
+        if (active == null) {
+            throw new IllegalStateException("No current dump entry");
+        }
+
         if (len + entryOffset > entrySize) {
             len = (int) (entrySize - entryOffset);
         }

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=1586935&r1=1586934&r2=1586935&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
Sun Apr 13 08:32:47 2014
@@ -871,6 +871,9 @@ public class SevenZFile implements Close
      *             if an I/O error has occurred
      */
     public int read() throws IOException {
+        if (currentEntryInputStream == null) {
+            throw new IllegalStateException("No current 7z entry");
+        }
         return currentEntryInputStream.read();
     }
     
@@ -897,6 +900,9 @@ public class SevenZFile implements Close
      *             if an I/O error has occurred
      */
     public int read(byte[] b, int off, int len) throws IOException {
+        if (currentEntryInputStream == null) {
+            throw new IllegalStateException("No current 7z entry");
+        }
         return currentEntryInputStream.read(b, off, len);
     }
     

Modified: commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/sevenz/SevenZOutputFile.java
URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/sevenz/SevenZOutputFile.java?rev=1586935&r1=1586934&r2=1586935&view=diff
==============================================================================
--- commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/sevenz/SevenZOutputFile.java
(original)
+++ commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/sevenz/SevenZOutputFile.java
Sun Apr 13 08:32:47 2014
@@ -181,7 +181,7 @@ public class SevenZOutputFile implements
         compressedCrc32.reset();
         fileBytesWritten = 0;
     }
-    
+
     /**
      * Writes a byte to the current archive entry.
      * @param b The byte to be written.
@@ -272,6 +272,10 @@ public class SevenZOutputFile implements
     }
 
     private CountingOutputStream setupFileOutputStream() throws IOException {
+        if (files.isEmpty()) {
+            throw new IllegalStateException("No current 7z entry");
+        }
+
         OutputStream out = new OutputStreamWrapper();
         ArrayList<CountingOutputStream> moreStreams = new ArrayList<CountingOutputStream>();
         boolean first = true;

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=1586935&r1=1586934&r2=1586935&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
Sun Apr 13 08:32:47 2014
@@ -573,6 +573,10 @@ public class TarArchiveInputStream exten
             return -1;
         }
 
+        if (currEntry == null) {
+            throw new IllegalStateException("No current tar entry");
+        }
+
         numToRead = Math.min(numToRead, available());
         
         totalRead = is.read(buf, offset, numToRead);

Modified: commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveOutputStream.java
URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveOutputStream.java?rev=1586935&r1=1586934&r2=1586935&view=diff
==============================================================================
--- commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveOutputStream.java
(original)
+++ commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveOutputStream.java
Sun Apr 13 08:32:47 2014
@@ -265,7 +265,7 @@ public class TarArchiveOutputStream exte
      */
     @Override
     public void putArchiveEntry(ArchiveEntry archiveEntry) throws IOException {
-        if(finished) {
+        if (finished) {
             throw new IOException("Stream has already been finished");
         }
         TarArchiveEntry entry = (TarArchiveEntry) archiveEntry;
@@ -369,6 +369,9 @@ public class TarArchiveOutputStream exte
      */
     @Override
     public void write(byte[] wBuf, int wOffset, int numToWrite) throws IOException {
+        if (!haveUnclosedEntry) {
+            throw new IllegalStateException("No current tar entry");
+        }
         if (currBytes + numToWrite > currSize) {
             throw new IOException("request to write '" + numToWrite
                                   + "' bytes exceeds size in header of '"

Modified: commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveOutputStream.java
URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveOutputStream.java?rev=1586935&r1=1586934&r2=1586935&view=diff
==============================================================================
--- commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveOutputStream.java
(original)
+++ commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveOutputStream.java
Sun Apr 13 08:32:47 2014
@@ -753,6 +753,9 @@ public class ZipArchiveOutputStream exte
      */
     @Override
     public void write(byte[] b, int offset, int length) throws IOException {
+        if (entry == null) {
+            throw new IllegalStateException("No current entry");
+        }
         ZipUtil.checkRequestedFeatures(entry.entry);
         entry.hasWritten = true;
         if (entry.entry.getMethod() == DEFLATED) {



Mime
View raw message