diff --git a/src/crwimage_int.cpp b/src/crwimage_int.cpp index 4080c078..58f1f467 100644 --- a/src/crwimage_int.cpp +++ b/src/crwimage_int.cpp @@ -570,12 +570,11 @@ namespace Exiv2 { DataLocId CiffComponent::dataLocation(uint16_t tag) { - DataLocId di = invalidDataLocId; switch (tag & 0xc000) { - case 0x0000: di = valueData; break; - case 0x4000: di = directoryData; break; + case 0x0000: return valueData; + case 0x4000: return directoryData; + default: throw Error(kerCorruptedMetadata); } - return di; } // CiffComponent::dataLocation /*! diff --git a/src/crwimage_int.hpp b/src/crwimage_int.hpp index 3e45bb73..84997d29 100644 --- a/src/crwimage_int.hpp +++ b/src/crwimage_int.hpp @@ -74,7 +74,6 @@ namespace Exiv2 { //! Type to identify where the data is stored in a directory enum DataLocId { - invalidDataLocId, valueData, directoryData, lastDataLocId diff --git a/test/data/issue_841_poc.crw b/test/data/issue_841_poc.crw new file mode 100644 index 00000000..75e04b18 Binary files /dev/null and b/test/data/issue_841_poc.crw differ diff --git a/tests/bugfixes/github/test_issue_841.py b/tests/bugfixes/github/test_issue_841.py new file mode 100644 index 00000000..14ba1430 --- /dev/null +++ b/tests/bugfixes/github/test_issue_841.py @@ -0,0 +1,22 @@ +# -*- coding: utf-8 -*- + +from system_tests import CaseMeta, path, check_no_ASAN_UBSAN_errors + + +class InvalidDataLocationInCiffComponentDoRead(metaclass=CaseMeta): + """ + Regression test for the bug described in: + https://github.com/Exiv2/exiv2/issues/841 + + An invalid data location causes an assertion failure. + """ + url = "https://github.com/Exiv2/exiv2/issues/841" + + filename = path("$data_path/issue_841_poc.crw") + commands = ["$exiv2 $filename"] + stdout = [""] + stderr = [ + """$exiv2_exception_message $filename: +$kerCorruptedMetadata +"""] + retval = [1]