Skip to content

Commit fcbc60b

Browse files
committed
PDFBOX-6106: catch incorrect type when in strict mode
git-svn-id: https://svn.apache.org/repos/asf/pdfbox/trunk@1930057 13f79535-47bb-0310-9956-ffa450edef68
1 parent 25f71f6 commit fcbc60b

File tree

2 files changed

+45
-4
lines changed

2 files changed

+45
-4
lines changed

xmpbox/src/main/java/org/apache/xmpbox/xml/DomXmpParser.java

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -280,12 +280,20 @@ private void parseDescriptionRootAttr(XMPMetadata xmp, Element description, Attr
280280
PropertyType type = checkPropertyDefinition(xmp,
281281
new QName(attr.getNamespaceURI(), attr.getLocalName()));
282282

283-
//Default to text if no type is found
284-
if( type == null)
283+
// PDFBOX-2318, PDFBOX-6106: Default to text if no type is found
284+
if (type == null)
285285
{
286-
type = TypeMapping.createPropertyType(Types.Text, Cardinality.Simple);
286+
if (strictParsing)
287+
{
288+
throw new XmpParsingException(ErrorType.InvalidType, "No type defined for {" + attr.getNamespaceURI() + "}"
289+
+ attr.getLocalName());
290+
}
291+
else
292+
{
293+
type = TypeMapping.createPropertyType(Types.Text, Cardinality.Simple);
294+
}
287295
}
288-
296+
289297
try
290298
{
291299
AbstractSimpleProperty sp = tm.instanciateSimpleProperty(namespace, schema.getPrefix(),

xmpbox/src/test/java/org/apache/xmpbox/xml/DomXmpParserTest.java

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,4 +83,37 @@ void testPDFBox5976() throws XmpParsingException
8383
Assertions.assertEquals("B", xmp.getPDFAIdentificationSchema().getConformance());
8484
Assertions.assertEquals((Integer) 3, xmp.getPDFAIdentificationSchema().getPart());
8585
}
86+
87+
/**
88+
* PDFBOX-6106: Check that "pdf:CreationDate='2004-01-30T17:21:50Z'" is detected as incorrect.
89+
* (Only Keywords, PDFVersion, and Producer are allowed in strict mode)
90+
*
91+
* @throws XmpParsingException
92+
*/
93+
@Test
94+
void testPDFBox6106() throws XmpParsingException
95+
{
96+
// from file 001358.pdf
97+
String s = "<?xpacket begin='' id='W5M0MpCehiHzreSzNTczkc9d' bytes='647'?>\n" +
98+
"<rdf:RDF xmlns:rdf='http://www.w3.org/1999/02/22-rdf-syntax-ns#'\n" +
99+
" xmlns:iX='http://ns.adobe.com/iX/1.0/'>\n" +
100+
" <rdf:Description about=''\n" +
101+
" xmlns='http://ns.adobe.com/pdf/1.3/'\n" +
102+
" xmlns:pdf='http://ns.adobe.com/pdf/1.3/'\n" +
103+
" pdf:CreationDate='2004-01-30T17:21:50Z'\n" +
104+
" pdf:ModDate='2004-01-30T17:21:50Z'\n" +
105+
" pdf:Producer='Acrobat Distiller 5.0.5 (Windows)'/>\n" +
106+
" <rdf:Description about=''\n" +
107+
" xmlns='http://ns.adobe.com/xap/1.0/'\n" +
108+
" xmlns:xap='http://ns.adobe.com/xap/1.0/'\n" +
109+
" xap:CreateDate='2004-01-30T17:21:50Z'\n" +
110+
" xap:ModifyDate='2004-01-30T17:21:50Z'\n" +
111+
" xap:MetadataDate='2004-01-30T17:21:50Z'/>\n" +
112+
"</rdf:RDF><?xpacket end='r'?>";
113+
DomXmpParser xmpParser = new DomXmpParser();
114+
XmpParsingException ex = Assertions.assertThrows(
115+
XmpParsingException.class,
116+
() -> xmpParser.parse(s.getBytes(StandardCharsets.UTF_8)));
117+
Assertions.assertEquals("No type defined for {http://ns.adobe.com/pdf/1.3/}CreationDate", ex.getMessage());
118+
}
86119
}

0 commit comments

Comments
 (0)