[ 
https://issues.apache.org/jira/browse/PDFBOX-2402?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14168123#comment-14168123
 ] 

Tilman Hausherr commented on PDFBOX-2402:
-----------------------------------------

Your patch works with a test file I created, but there's one thing I wonder 
about: do we need the read? This code works as well:
{code}
if (!endObjectKey.startsWith("endobj"))
{
    if (isLenient)
    {
        LOG.warn("Object (" + readObjNr + ":" + readObjGen + ") at offset "
                + offsetOrObjstmObNr + " does not end with 'endobj' but with '"
                + endObjectKey + "'");
    }
    else
    {
        throw new IOException("Object (" + readObjNr + ":" + readObjGen
                + ") at offset " + offsetOrObjstmObNr
                + " does not end with 'endobj' but with '" + endObjectKey + 
"'");
    }
}
{code}
The parser is non-sequential, i.e. it doesn't have to position to the next 
object correctly.

> NonSequentialPDFParser cannot recover from spurious closing brackets
> --------------------------------------------------------------------
>
>                 Key: PDFBOX-2402
>                 URL: https://issues.apache.org/jira/browse/PDFBOX-2402
>             Project: PDFBox
>          Issue Type: Bug
>          Components: Parsing
>    Affects Versions: 2.0.0
>            Reporter: Michele Balistreri
>            Assignee: Tilman Hausherr
>             Fix For: 2.0.0
>
>         Attachments: NonSequentialPDFParser.patch, file screenshot.png
>
>
> The NonSequentialPDFParser fails if an object has a spurious closing tag (for 
> example, a PDFArray with two closing brackets). In lenient mode, it would be 
> good to at least attempt recovering from that. The attached patch, instead of 
> throwing an exception in case the endObject string is not "endobj" or " obj", 
> skips a character (the spurious character) and tries reading a string. It 
> continues until either the file ends or an "endobj" is found.
> I have a document where this worked but I am not allowed to upload it, 
> unfortunately. In any case the patch cannot make things worse, since it 
> replaces throwing an exception with at least attempting to recover from it.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to