Details
-
Bug
-
Status: Closed
-
Major
-
Resolution: Fixed
-
3.0.1 PDFBox, 4.0.0
-
None
Description
David Klika posted the following bug report on dev@
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.