Skip to content

Commit daba47a

Browse files
committed
PDFBOX-5908: avoid negative values
git-svn-id: https://svn.apache.org/repos/asf/pdfbox/trunk@1922153 13f79535-47bb-0310-9956-ffa450edef68
1 parent 78257f6 commit daba47a

File tree

1 file changed

+5
-2
lines changed
  • pdfbox/src/main/java/org/apache/pdfbox/filter

1 file changed

+5
-2
lines changed

pdfbox/src/main/java/org/apache/pdfbox/filter/Filter.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -272,8 +272,11 @@ public static RandomAccessRead decode(InputStream encoded, List<Filter> filterLi
272272
length = length <= 0 ? RandomAccessReadBuffer.DEFAULT_CHUNK_SIZE_4KB : length;
273273
// we don't know the size of the decoded stream, just estimate a 4 times bigger size than the encoded stream
274274
// use the estimated stream size as chunk size, use the default chunk size as limit to avoid to big values
275-
randomAccessWriteBuffer = new RandomAccessReadWriteBuffer(
276-
Math.min(length << 2, RandomAccessReadBuffer.DEFAULT_CHUNK_SIZE_4KB));
275+
length <<= 2;
276+
length = length <= 0 ? // PDFBOX-5908 avoid invalid values (again)
277+
RandomAccessReadBuffer.DEFAULT_CHUNK_SIZE_4KB :
278+
Math.min(length, RandomAccessReadBuffer.DEFAULT_CHUNK_SIZE_4KB);
279+
randomAccessWriteBuffer = new RandomAccessReadWriteBuffer(length);
277280
output = new RandomAccessOutputStream(randomAccessWriteBuffer);
278281
try
279282
{

0 commit comments

Comments
 (0)