Skip to content

Commit d4480ae

Browse files
committed
PDFBOX-6134: catch bad date + add test
git-svn-id: https://svn.apache.org/repos/asf/pdfbox/trunk@1930871 13f79535-47bb-0310-9956-ffa450edef68
1 parent 03d1fec commit d4480ae

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

xmpbox/src/main/java/org/apache/xmpbox/DateConverter.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,11 @@ public static Calendar toCalendar(String date) throws IOException
106106
{
107107
date = date.substring(2);
108108
}
109+
int posOfT = date.indexOf('T');
110+
if (posOfT != 10 && posOfT != -1)
111+
{
112+
throw new IOException("Error converting date:" + date);
113+
}
109114

110115
date = date.replaceAll("[-:T]", "");
111116

xmpbox/src/test/java/org/apache/xmpbox/DateConverterTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ void testDateConversion() throws IOException
116116
assertThrows(IOException.class, () -> DateConverter.toCalendar("2008-12-02T21:04:0Z"));
117117
assertThrows(IOException.class, () -> DateConverter.toCalendar("0-01-01T00:00:00Z"));
118118
assertThrows(IOException.class, () -> DateConverter.toCalendar("2009-03-16T01:15:19-0-4:00"));
119+
assertThrows(IOException.class, () -> DateConverter.toCalendar("0-00-00T00:00:00-04:00"));
119120

120121
// Test missing seconds
121122
assertEquals(DateConverter.toCalendar("2015-12-08T12:07:00-05:00"),

0 commit comments

Comments
 (0)