You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pdfbox.apache.org by ti...@apache.org on 2020/05/29 17:51:10 UTC
svn commit: r1878283 -
/pdfbox/branches/1.8/pdfbox/src/main/java/org/apache/pdfbox/filter/FlateFilter.java
Author: tilman
Date: Fri May 29 17:51:10 2020
New Revision: 1878283
URL: http://svn.apache.org/viewvc?rev=1878283&view=rev
Log:
PDFBOX-4849: avoid Flate leak, as suggested by Christof Lorenz
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=1878283&r1=1878282&r2=1878283&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 Fri May 29 17:51:10 2020
@@ -126,41 +126,47 @@ public class FlateFilter implements Filt
inflater.setInput(buf,0,read);
byte[] res = new byte[1024];
boolean dataWritten = false;
- while(true)
- {
- int resRead = 0;
- try
- {
- resRead = inflater.inflate(res);
- }
- catch(DataFormatException exception)
- {
- if (dataWritten)
+ try
+ {
+ while(true)
+ {
+ int resRead = 0;
+ try
{
- // some data could be read -> don't throw an exception
- LOG.warn("FlateFilter: premature end of stream due to a DataFormatException");
- break;
+ resRead = inflater.inflate(res);
}
- else
+ catch(DataFormatException exception)
{
- // nothing could be read -> re-throw exception
- throw 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)
+ {
+ break;
+ }
+ read = in.read(buf);
+ inflater.setInput(buf,0,read);
}
- if(resRead != 0)
- {
- out.write(res,0,resRead);
- dataWritten = true;
- continue;
- }
- if(inflater.finished() || inflater.needsDictionary() || in.available() == 0)
- {
- break;
- }
- read = in.read(buf);
- inflater.setInput(buf,0,read);
}
- inflater.end();
+ finally
+ {
+ inflater.end();
+ }
}
out.close();
}