[
https://issues.apache.org/jira/browse/PDFBOX-6334?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18148047#comment-18148047
]
ASF subversion and git services commented on PDFBOX-6334:
---------------------------------------------------------
Commit 1940539 from Tilman Hausherr in branch 'pdfbox/branches/2.0'
[ https://svn.apache.org/r1940539 ]
PDFBOX-6334: avoid StringIndexOutOfBoundsException, by Martin Mirchev
> StringIndexOutOfBoundsException in DomXmpParser for a truncated xpacket end
> instruction
> ---------------------------------------------------------------------------------------
>
> Key: PDFBOX-6334
> URL: https://issues.apache.org/jira/browse/PDFBOX-6334
> Project: PDFBox
> Issue Type: Bug
> Components: XmpBox
> Affects Versions: 3.0.8 PDFBox, 4.0.0
> Reporter: Martin Mirchev
> Priority: Major
>
> {{DomXmpParser.parseEndPacket()}} reads {{charAt(5)}} after checking only
> that the processing instruction data starts with {{end=}}. Metadata that ends
> with {{<?xpacket end=?>}} or {{<?xpacket end='?>}} makes
> {{DomXmpParser.parse()}} throw a {{StringIndexOutOfBoundsException}} instead
> of the {{XmpParsingException}} ({{XpacketBadEnd}}) that the method throws for
> other bad values:
> {code}
> java.lang.StringIndexOutOfBoundsException: String index out of range: 5
> at java.base/java.lang.StringLatin1.charAt(StringLatin1.java:48)
> at
> org.apache.xmpbox.xml.DomXmpParser.parseEndPacket(DomXmpParser.java:929)
> {code}
> To reproduce, parse {{<?xpacket begin=""
> id="W5M0MpCehiHzreSzNTczkc9d"?><x:xmpmeta xmlns:x="adobe:ns:meta/"><rdf:RDF
> xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"></rdf:RDF></x:xmpmeta><?xpacket
> end=?>}} with {{new DomXmpParser().parse(bytes)}}; with {{end='w'}} instead
> it parses. Each result was the same in 3 runs.
> A possible change; with it, both truncated forms throw
> {{XmpParsingException}} and {{end='w'}} and {{end="r"}} still parse:
> {code}
> --- a/xmpbox/src/main/java/org/apache/xmpbox/xml/DomXmpParser.java
> +++ b/xmpbox/src/main/java/org/apache/xmpbox/xml/DomXmpParser.java
> @@ -926,6 +926,11 @@
> // should be ignored
> if (xpackData.startsWith("end="))
> {
> + if (xpackData.length() < 7)
> + {
> + throw new XmpParsingException(ErrorType.XpacketBadEnd,
> + "Expected xpacket 'end' attribute with value 'r' or
> 'w' ");
> + }
> char end = xpackData.charAt(5);
> // check value (5 for end='X')
> if (end != 'r' && end != 'w')
> {code}
> The module unit tests pass with the change (io, fontbox, xmpbox, pdfbox;
> trunk fff879b).
> This issue was found by an LLM-assisted tool and verified manually.
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]