From daba47ac75a315a8bb1ab29c87af336f710ce7a4 Mon Sep 17 00:00:00 2001 From: Tilman Hausherr Date: Wed, 27 Nov 2024 09:54:13 +0000 Subject: [PATCH] PDFBOX-5908: avoid negative values git-svn-id: https://svn.apache.org/repos/asf/pdfbox/trunk@1922153 13f79535-47bb-0310-9956-ffa450edef68 --- pdfbox/src/main/java/org/apache/pdfbox/filter/Filter.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) 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 8e9824d88fc..04a9f155041 100644 --- a/pdfbox/src/main/java/org/apache/pdfbox/filter/Filter.java +++ b/pdfbox/src/main/java/org/apache/pdfbox/filter/Filter.java @@ -272,8 +272,11 @@ public static RandomAccessRead decode(InputStream encoded, List filterLi length = length <= 0 ? RandomAccessReadBuffer.DEFAULT_CHUNK_SIZE_4KB : length; // 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 - randomAccessWriteBuffer = new RandomAccessReadWriteBuffer( - Math.min(length << 2, RandomAccessReadBuffer.DEFAULT_CHUNK_SIZE_4KB)); + length <<= 2; + length = length <= 0 ? // PDFBOX-5908 avoid invalid values (again) + RandomAccessReadBuffer.DEFAULT_CHUNK_SIZE_4KB : + Math.min(length, RandomAccessReadBuffer.DEFAULT_CHUNK_SIZE_4KB); + randomAccessWriteBuffer = new RandomAccessReadWriteBuffer(length); output = new RandomAccessOutputStream(randomAccessWriteBuffer); try {