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

Martin Mirchev commented on PDFBOX-6064:
----------------------------------------

The misleading message comes from {{inlineImageDepth}}: it is decremented only 
when the inline image dictionary is
followed by the ID operator. When the dictionary ends some other way (here 
because of {{/CS 40 0 R}}), the depth
stays at 1, and the next, valid BI on the page fails with "Nested 'BI' operator 
not allowed". In the attached
{{inline-bad-first.pdf}} the content stream is "one", an inline image whose 
dictionary ends with a number, "two", a
valid inline image, "three"; {{getText()}} throws that IOException and returns 
nothing, while {{inline-ok.pdf}}
(both images valid) gives "one two three".

Decrementing the depth when the BI is finished, with or without image data, 
fixes it; with this change
{{inline-bad-first.pdf}} gives "one two three", and the io, fontbox, xmpbox and 
pdfbox unit tests pass:

{code}
diff --git 
a/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/PDFStreamParser.java 
b/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/PDFStreamParser.java
index 4ea45b3..5978628 100644
--- a/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/PDFStreamParser.java
+++ b/pdfbox/src/main/java/org/apache/pdfbox/pdfparser/PDFStreamParser.java
@@ -276,7 +276,6 @@ public class PDFStreamParser extends COSParser
                                     (source.isClosed() ? "EOF" : 
source.getPosition()));
                         }
                         beginImageOP.setImageData(imageData.getImageData());
-                        inlineImageDepth--;
                     }
                     else
                     {
@@ -284,6 +283,8 @@ public class PDFStreamParser extends COSParser
                                 nextToken, (source.isClosed() ? "EOF" : 
source.getPosition()), 
                                 OperatorName.BEGIN_INLINE_IMAGE_DATA);
                     }
+                    // this inline image is finished, with or without image 
data
+                    inlineImageDepth--;
                 }
                 return beginImageOP;
             case 'I':
{code}

This was found by an LLM-assisted tool and verified manually.


> IOException: Nested 'BI' operator not allowed
> ---------------------------------------------
>
>                 Key: PDFBOX-6064
>                 URL: https://issues.apache.org/jira/browse/PDFBOX-6064
>             Project: PDFBox
>          Issue Type: Bug
>          Components: Rendering
>    Affects Versions: 2.0.34, 3.0.5 PDFBox
>            Reporter: Tilman Hausherr
>            Priority: Major
>         Attachments: PDFBOX-6064-0111938-BadInlineImageDict.pdf, 
> PDFBOX-6064-0111938-BadInlineImageDict.txt, inline-bad-first.pdf, 
> inline-ok.pdf
>
>
> The error message is misleading, the real cause is this "/CS 40 0 R" between 
> BI and ID. A name is expected but there is an indirect object reference. I 
> have no real fix and will improve logging a bit for now.



--
This message was sent by Atlassian Jira
(v10.3.26#10030026)

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to