diff --git a/pdfbox/src/main/java/org/apache/pdfbox/filter/Filter.java b/pdfbox/src/main/java/org/apache/pdfbox/filter/Filter.java index 24f1b27f37a..962c60396de 100644 --- a/pdfbox/src/main/java/org/apache/pdfbox/filter/Filter.java +++ b/pdfbox/src/main/java/org/apache/pdfbox/filter/Filter.java @@ -270,13 +270,13 @@ public static RandomAccessRead decode(InputStream encoded, List filterLi } // we don't know the size of the decoded stream, just estimate a 4 times bigger size than the encoded stream // use the estimated stream size as chunk size, use the default chunk size as limit to avoid to big values - if (length >= RandomAccessReadBuffer.DEFAULT_CHUNK_SIZE_4KB / 4) + if (length <= 0 || length >= RandomAccessReadBuffer.DEFAULT_CHUNK_SIZE_4KB / 4) { length = RandomAccessReadBuffer.DEFAULT_CHUNK_SIZE_4KB; } else { - length = Math.min(length << 2, RandomAccessReadBuffer.DEFAULT_CHUNK_SIZE_4KB); + length = length * 4; } randomAccessWriteBuffer = new RandomAccessReadWriteBuffer((int) length); output = new RandomAccessOutputStream(randomAccessWriteBuffer);