Andreas Lehmkühler created PDFBOX-5764:
------------------------------------------

             Summary: Wrong chunksize when using a ByteBuffer to initialize a 
RandomAccessReadBuffer
                 Key: PDFBOX-5764
                 URL: https://issues.apache.org/jira/browse/PDFBOX-5764
             Project: PDFBox
          Issue Type: Bug
          Components: IO
    Affects Versions: 3.0.1 PDFBox, 4.0.0
            Reporter: Andreas Lehmkühler
            Assignee: Andreas Lehmkühler
             Fix For: 3.0.2 PDFBox, 4.0.0


David Klika posted the following bug report on dev@
{quote}
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:
{quote}
 
{code}
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)
{code}
{quote}
 

31556 is the buffer capacity, 20960 is its limit

 

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



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

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

Reply via email to