Skip to content

Commit

Permalink
PDFBOX-5675: never re-thrown a DataFormatException, simply use the al…
Browse files Browse the repository at this point in the history
…ready read data or an empty stream

git-svn-id: https://svn.apache.org/repos/asf/pdfbox/trunk@1919611 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
lehmi committed Aug 1, 2024
1 parent f081d98 commit d0ca245
Showing 1 changed file with 3 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ public final class FlateFilterDecoderStream extends FilterInputStream
private byte[] decodedData = new byte[4096];
// use nowrap mode to bypass zlib-header and checksum to avoid a DataFormatException
private final Inflater inflater = new Inflater(true);
private boolean dataDecoded = false;

/**
* Constructor.
Expand Down Expand Up @@ -84,22 +83,13 @@ private boolean fetch() throws IOException
try
{
bytesDecoded = inflater.inflate(decodedData);
dataDecoded |= bytesDecoded > 0;
}
catch (DataFormatException exception)
{
isEOF = true;
if (dataDecoded)
{
// some data could be decoded -> don't throw an exception
LOG.warn("FlateFilter: premature end of stream due to a DataFormatException");
return false;
}
else
{
// nothing could be read -> re-throw exception wrapped in an IOException
throw new IOException(exception);
}
// don't throw an exception, use the already read data or an empty stream
LOG.warn("FlateFilter: premature end of stream due to a DataFormatException = {}",
exception.getMessage());
}
return true;
}
Expand Down

0 comments on commit d0ca245

Please sign in to comment.