diff --git a/src/exiv2.cpp b/src/exiv2.cpp index 1132603c..ce3fb5ec 100644 --- a/src/exiv2.cpp +++ b/src/exiv2.cpp @@ -1475,6 +1475,11 @@ namespace { modifyCmd.value_ = value; if (cmdId == reg) { + if (value.empty()) { + throw Exiv2::Error(Exiv2::kerErrorMessage, + Exiv2::toString(num) + ": " + _("Empty value for key") + + " `" + key + "'"); + } + // Registration needs to be done immediately as the new namespaces are // looked up during parsing of subsequent lines (to validate XMP keys). Exiv2::XmpProperties::registerNs(modifyCmd.value_, modifyCmd.key_); diff --git a/test/data/issue_1099_poc.bin b/test/data/issue_1099_poc.bin new file mode 100644 index 00000000..bf386ecb Binary files /dev/null and b/test/data/issue_1099_poc.bin differ diff --git a/test/data/issue_1099_poc.txt b/test/data/issue_1099_poc.txt new file mode 100644 index 00000000..3509efb7 Binary files /dev/null and b/test/data/issue_1099_poc.txt differ diff --git a/tests/bugfixes/github/test_issue_1099.py b/tests/bugfixes/github/test_issue_1099.py new file mode 100644 index 00000000..6d64b3d3 --- /dev/null +++ b/tests/bugfixes/github/test_issue_1099.py @@ -0,0 +1,27 @@ +# -*- coding: utf-8 -*- + +from system_tests import CaseMeta, path, check_no_ASAN_UBSAN_errors + + +class EmptyValueInCommandFile(metaclass=CaseMeta): + """ + Regression test for the bug described in: + https://github.com/Exiv2/exiv2/issues/1099 + + An empty value in the command file causes a std::out_of_range exception. + """ + url = "https://github.com/Exiv2/exiv2/issues/1099" + + filename1 = path("$data_path/issue_1099_poc.txt") + filename2 = path("$data_path/issue_1099_poc.bin") + commands = ["$exiv2 -m $filename1 mo $filename2"] + + stderr = [ + """$filename1, line 1: Empty value for key `Exiff.LfkInfo.GPSDa' +$exiv2exe: Error parsing -m option arguments +"""] + retval = [1] + + def compare_stdout(self, i, command, got_stdout, expected_stdout): + """ We don't care about the stdout, just don't crash """ + pass diff --git a/tests/suite.conf b/tests/suite.conf index f829b4cc..7f7cfcca 100644 --- a/tests/suite.conf +++ b/tests/suite.conf @@ -28,6 +28,7 @@ kerInvalidTypeValue: invalid type value detected in Image::printIFDStructure kerNotAJpeg : This does not look like a JPEG image kerNoImageInInputData: Input data does not contain a valid image addition_overflow_message: Overflow in addition +exiv2exe: exiv2${ENV:binary_extension} exiv2_exception_message: Exiv2 exception in print action for file exiv2_overflow_exception_message: std::overflow_error exception in print action for file exception_in_extract: Exiv2 exception in extract action for file