diff --git a/src/tags_int.cpp b/src/tags_int.cpp index 2b21de04..6466ca19 100644 --- a/src/tags_int.cpp +++ b/src/tags_int.cpp @@ -3265,8 +3265,8 @@ namespace Exiv2 { } std::string stringValue = value.toString(); - if (stringValue.at(19) == 'Z') { - stringValue = stringValue.substr(0, 19); + if (stringValue.size() == 20 && stringValue.at(19) == 'Z') { + stringValue.pop_back(); } std::replace(stringValue.begin(), stringValue.end(), 'T', ' '); std::replace(stringValue.begin(), stringValue.end(), '-', ':'); diff --git a/test/data/issue_1918_poc.jpg b/test/data/issue_1918_poc.jpg new file mode 100644 index 00000000..43aa9bc6 Binary files /dev/null and b/test/data/issue_1918_poc.jpg differ diff --git a/tests/bugfixes/github/test_issue_1918.py b/tests/bugfixes/github/test_issue_1918.py new file mode 100644 index 00000000..4ee54ab4 --- /dev/null +++ b/tests/bugfixes/github/test_issue_1918.py @@ -0,0 +1,17 @@ +# -*- coding: utf-8 -*- + +from system_tests import CaseMeta, path, check_no_ASAN_UBSAN_errors + +class PrintXmpDateOutOfBoundsIndex19(metaclass=CaseMeta): + """ + Regression test for the bug described in: + https://github.com/Exiv2/exiv2/issues/1918 + """ + url = "https://github.com/Exiv2/exiv2/issues/1918" + + filename = path("$data_path/issue_1918_poc.jpg") + commands = ["$exiv2 -px $filename"] + stderr = [""] + retval = [0] + + compare_stdout = check_no_ASAN_UBSAN_errors