Skip to content

Commit

Permalink
PDFBOX-5908: avoid negative values
Browse files Browse the repository at this point in the history
git-svn-id: https://svn.apache.org/repos/asf/pdfbox/trunk@1922153 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
THausherr committed Nov 27, 2024
1 parent 78257f6 commit daba47a
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions pdfbox/src/main/java/org/apache/pdfbox/filter/Filter.java
Original file line number Diff line number Diff line change
Expand Up @@ -272,8 +272,11 @@ public static RandomAccessRead decode(InputStream encoded, List<Filter> 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
{
Expand Down

0 comments on commit daba47a

Please sign in to comment.