Author: tilman
Date: Fri Nov 28 13:38:17 2025
New Revision: 1930058
Log:
PDFBOX-6106: catch incorrect type when in strict mode
Modified:
pdfbox/branches/3.0/xmpbox/src/main/java/org/apache/xmpbox/xml/DomXmpParser.java
pdfbox/branches/3.0/xmpbox/src/test/java/org/apache/xmpbox/xml/DomXmpParserTest.java
Modified:
pdfbox/branches/3.0/xmpbox/src/main/java/org/apache/xmpbox/xml/DomXmpParser.java
==============================================================================
---
pdfbox/branches/3.0/xmpbox/src/main/java/org/apache/xmpbox/xml/DomXmpParser.java
Fri Nov 28 13:38:12 2025 (r1930057)
+++
pdfbox/branches/3.0/xmpbox/src/main/java/org/apache/xmpbox/xml/DomXmpParser.java
Fri Nov 28 13:38:17 2025 (r1930058)
@@ -279,13 +279,21 @@ public class DomXmpParser
ComplexPropertyContainer container = schema.getContainer();
PropertyType type = checkPropertyDefinition(xmp,
new QName(attr.getNamespaceURI(), attr.getLocalName()));
-
- //Default to text if no type is found
- if( type == null)
+
+ // PDFBOX-2318, PDFBOX-6106: Default to text if no type is found
+ if (type == null)
{
- type = TypeMapping.createPropertyType(Types.Text,
Cardinality.Simple);
+ if (strictParsing)
+ {
+ throw new XmpParsingException(ErrorType.InvalidType, "No
type defined for {" + attr.getNamespaceURI() + "}"
+ + attr.getLocalName());
+ }
+ else
+ {
+ type = TypeMapping.createPropertyType(Types.Text,
Cardinality.Simple);
+ }
}
-
+
try
{
AbstractSimpleProperty sp =
tm.instanciateSimpleProperty(namespace, schema.getPrefix(),
Modified:
pdfbox/branches/3.0/xmpbox/src/test/java/org/apache/xmpbox/xml/DomXmpParserTest.java
==============================================================================
---
pdfbox/branches/3.0/xmpbox/src/test/java/org/apache/xmpbox/xml/DomXmpParserTest.java
Fri Nov 28 13:38:12 2025 (r1930057)
+++
pdfbox/branches/3.0/xmpbox/src/test/java/org/apache/xmpbox/xml/DomXmpParserTest.java
Fri Nov 28 13:38:17 2025 (r1930058)
@@ -83,4 +83,37 @@ class DomXmpParserTest
Assertions.assertEquals("B",
xmp.getPDFAIdentificationSchema().getConformance());
Assertions.assertEquals((Integer) 3,
xmp.getPDFAIdentificationSchema().getPart());
}
+
+ /**
+ * PDFBOX-6106: Check that "pdf:CreationDate='2004-01-30T17:21:50Z'" is
detected as incorrect.
+ * (Only Keywords, PDFVersion, and Producer are allowed in strict mode)
+ *
+ * @throws XmpParsingException
+ */
+ @Test
+ void testPDFBox6106() throws XmpParsingException
+ {
+ // from file 001358.pdf
+ String s = "<?xpacket begin='' id='W5M0MpCehiHzreSzNTczkc9d'
bytes='647'?>\n" +
+ "<rdf:RDF
xmlns:rdf='http://www.w3.org/1999/02/22-rdf-syntax-ns#'\n" +
+ " xmlns:iX='http://ns.adobe.com/iX/1.0/'>\n" +
+ " <rdf:Description about=''\n" +
+ "
xmlns='http://ns.adobe.com/pdf/1.3/'\n" +
+ "
xmlns:pdf='http://ns.adobe.com/pdf/1.3/'\n" +
+ "
pdf:CreationDate='2004-01-30T17:21:50Z'\n" +
+ " pdf:ModDate='2004-01-30T17:21:50Z'\n" +
+ " pdf:Producer='Acrobat Distiller 5.0.5
(Windows)'/>\n" +
+ " <rdf:Description about=''\n" +
+ "
xmlns='http://ns.adobe.com/xap/1.0/'\n" +
+ "
xmlns:xap='http://ns.adobe.com/xap/1.0/'\n" +
+ "
xap:CreateDate='2004-01-30T17:21:50Z'\n" +
+ "
xap:ModifyDate='2004-01-30T17:21:50Z'\n" +
+ "
xap:MetadataDate='2004-01-30T17:21:50Z'/>\n" +
+ "</rdf:RDF><?xpacket end='r'?>";
+ DomXmpParser xmpParser = new DomXmpParser();
+ XmpParsingException ex = Assertions.assertThrows(
+ XmpParsingException.class,
+ () -> xmpParser.parse(s.getBytes(StandardCharsets.UTF_8)));
+ Assertions.assertEquals("No type defined for
{http://ns.adobe.com/pdf/1.3/}CreationDate", ex.getMessage());
+ }
}