pdfbox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From le...@apache.org
Subject svn commit: r1709182 - /pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/filter/FlateFilter.java
Date Sat, 17 Oct 2015 14:56:14 GMT
Author: lehmi
Date: Sat Oct 17 14:56:14 2015
New Revision: 1709182

URL: http://svn.apache.org/viewvc?rev=1709182&view=rev
Log:
PDFBOX-2976: use a reduced buffer size when decompressing data to read as much data as possible
even if the stream is corrupt

Modified:
    pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/filter/FlateFilter.java

Modified: pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/filter/FlateFilter.java
URL: http://svn.apache.org/viewvc/pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/filter/FlateFilter.java?rev=1709182&r1=1709181&r2=1709182&view=diff
==============================================================================
--- pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/filter/FlateFilter.java (original)
+++ pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/filter/FlateFilter.java Sat
Oct 17 14:56:14 2015
@@ -35,9 +35,8 @@ import org.apache.pdfbox.cos.COSName;
 /**
  * This is the used for the FlateDecode filter.
  *
- * @author <a href="mailto:ben@benlitchfield.com">Ben Litchfield</a>
+ * @author Ben Litchfield
  * @author Marcel Kammer
- * @version $Revision: 1.12 $
  */
 public class FlateFilter implements Filter
 {
@@ -122,13 +121,33 @@ public class FlateFilter implements Filt
         { 
             Inflater inflater = new Inflater(); 
             inflater.setInput(buf,0,read); 
-            byte[] res = new byte[2048]; 
+            byte[] res = new byte[32];
+            boolean dataWritten = false;
             while(true) 
             { 
-                int resRead = inflater.inflate(res); 
+                int resRead = 0;
+                try
+                {
+                    resRead = inflater.inflate(res);
+                }
+                catch(DataFormatException exception)
+                {
+                    if (dataWritten)
+                    {
+                        // some data could be read -> don't throw an exception
+                        LOG.warn("FlateFilter: premature end of stream due to a DataFormatException");
+                        break;
+                    }
+                    else
+                    {
+                        // nothing could be read -> re-throw exception
+                        throw exception;
+                    }
+                }
                 if(resRead != 0) 
                 { 
                     out.write(res,0,resRead); 
+                    dataWritten = true;
                     continue; 
                 } 
                 if(inflater.finished() || inflater.needsDictionary() || in.available() ==
0) 



Mime
View raw message