From d0ca2451608f21f6e2c2568278d89051fcebc996 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20Lehmk=C3=BChler?= Date: Thu, 1 Aug 2024 05:37:32 +0000 Subject: [PATCH] PDFBOX-5675: never re-thrown a DataFormatException, simply use the already read data or an empty stream git-svn-id: https://svn.apache.org/repos/asf/pdfbox/trunk@1919611 13f79535-47bb-0310-9956-ffa450edef68 --- .../pdfbox/filter/FlateFilterDecoderStream.java | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) diff --git a/pdfbox/src/main/java/org/apache/pdfbox/filter/FlateFilterDecoderStream.java b/pdfbox/src/main/java/org/apache/pdfbox/filter/FlateFilterDecoderStream.java index fb2dee4f2bb..77791608683 100644 --- a/pdfbox/src/main/java/org/apache/pdfbox/filter/FlateFilterDecoderStream.java +++ b/pdfbox/src/main/java/org/apache/pdfbox/filter/FlateFilterDecoderStream.java @@ -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. @@ -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; }