diff --git a/src/value.cpp b/src/value.cpp index 8ea02d62..dd7aff4f 100644 --- a/src/value.cpp +++ b/src/value.cpp @@ -913,7 +913,10 @@ namespace Exiv2 { std::memcpy(b, reinterpret_cast(buf), 8); int scanned = sscanf(b, "%4d%2d%2d", &date_.year, &date_.month, &date_.day); - if (scanned != 3) { + if ( scanned != 3 + || date_.year < 0 + || date_.month < 1 || date_.month > 12 + || date_.day < 1 || date_.day > 31) { #ifndef SUPPRESS_WARNINGS EXV_WARNING << Error(kerUnsupportedDateFormat) << "\n"; #endif @@ -931,9 +934,12 @@ namespace Exiv2 { #endif return 1; } - int scanned = sscanf(buf.c_str(), "%4d-%d-%d", + int scanned = sscanf(buf.c_str(), "%4d-%2d-%2d", &date_.year, &date_.month, &date_.day); - if (scanned != 3) { + if ( scanned != 3 + || date_.year < 0 + || date_.month < 1 || date_.month > 12 + || date_.day < 1 || date_.day > 31) { #ifndef SUPPRESS_WARNINGS EXV_WARNING << Error(kerUnsupportedDateFormat) << "\n"; #endif @@ -954,7 +960,7 @@ namespace Exiv2 { // sprintf wants to add the null terminator, so use oversized buffer char temp[9]; - int wrote = sprintf(temp, "%04d%02d%02d", date_.year, date_.month, date_.day); + int wrote = snprintf(temp, sizeof(temp), "%04d%02d%02d", date_.year, date_.month, date_.day); assert(wrote == 8); std::memcpy(buf, temp, wrote); return wrote; diff --git a/test/data/issue_1713_poc.xmp b/test/data/issue_1713_poc.xmp new file mode 100644 index 00000000..009b87c5 --- /dev/null +++ b/test/data/issue_1713_poc.xmp @@ -0,0 +1,87 @@ + + + + + + + Blue Square Test File - .jpg + Blue Square Test File - .jpg + Blaues Quadrat Test Datei - .jpg + + + + + XMPFiles BlueSquare test file, created in Photoshop CS2, saved as .psd, .jpg, and .tif. + + + + + XMP + Blue Square + test file + Photoshop + .jpg + + + + + + 8 + 8 + 8 + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/tests/bugfixes/github/test_issue_1713.py b/tests/bugfixes/github/test_issue_1713.py new file mode 100644 index 00000000..00fd51b5 --- /dev/null +++ b/tests/bugfixes/github/test_issue_1713.py @@ -0,0 +1,26 @@ +# -*- coding: utf-8 -*- + +from system_tests import CaseMeta, path + + +class InvalidDateXMP(metaclass=CaseMeta): + """ + Regression test for the bug described in: + https://github.com/Exiv2/exiv2/issues/1713 + """ + url = "https://github.com/Exiv2/exiv2/issues/1713" + + filename = path("$data_path/issue_1713_poc.xmp") + commands = ["$exiv2 -Ph $filename"] + + stderr = [ +"""Warning: Failed to convert Xmp.xmp.CreateDate to Exif.Photo.DateTimeDigitized (Day is out of range) +Exiv2 exception in print action for file $filename: +Xmpdatum::copy: Not supported +""" +] + retval = [1] + + def compare_stdout(self, i, command, got_stdout, expected_stdout): + """ We don't care about the stdout, just don't crash """ + pass