Hi David,

thanks for the bug report. You are right and the proposed solution seems to be a valid fix.

I've created https://issues.apache.org/jira/browse/PDFBOX-5764 to handle it.

Andreas

Am 08.02.24 um 00:00 schrieb david.kl...@atlas.cz:
Hello

I think that this is not correct in some cases:

   public RandomAccessReadBuffer(ByteBuffer input) {

         chunkSize = input.capacity();

IMHO input.limit() shoud be used instead of input.capacity().

When it matters: I have a ByteArrayOutputStream to that is written a PDF
document. Later I want to open the PDF document using PDFBox again. If I use
part of the internal buffer directly (without copying), eg.
ByteBuffer.wrap(bos.getInternalBuffer(), 0, bos.size()), I get exception
like that:

java.lang.IllegalArgumentException: newPosition > limit: (31556 > 20960)

                 at
java.base/java.nio.Buffer.createPositionException(Buffer.java:352)

                 at java.base/java.nio.Buffer.position(Buffer.java:327)

                 at
java.base/java.nio.ByteBuffer.position(ByteBuffer.java:1551)

                 at
java.base/java.nio.ByteBuffer.position(ByteBuffer.java:285)

                 at
org.apache.pdfbox.io.RandomAccessReadBuffer.seek(RandomAccessReadBuffer.java
:187)

                 at
org.apache.pdfbox.pdfparser.COSParser.getStartxrefOffset(COSParser.java:506)

                 at
org.apache.pdfbox.pdfparser.COSParser.retrieveTrailer(COSParser.java:259)

                 at
org.apache.pdfbox.pdfparser.PDFParser.initialParse(PDFParser.java:107)

                 at
org.apache.pdfbox.pdfparser.PDFParser.parse(PDFParser.java:171)

                 at
org.apache.pdfbox.pdfparser.PDFParser.parse(PDFParser.java:136)

                 at org.apache.pdfbox.Loader.loadPDF(Loader.java:466)

                 at org.apache.pdfbox.Loader.loadPDF(Loader.java:369)

31556 is the buffer capacity, 20960 is its limit

I think the buffer should not be read beyond its limit.

Regards

David Klika



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@pdfbox.apache.org
For additional commands, e-mail: dev-h...@pdfbox.apache.org

Reply via email to