diff --git a/src/nikonmn_int.cpp b/src/nikonmn_int.cpp index f60fd984..e038825a 100644 --- a/src/nikonmn_int.cpp +++ b/src/nikonmn_int.cpp @@ -370,8 +370,12 @@ namespace Exiv2 { const ExifData*) { if (value.count() >= 1) { - unsigned long focusArea = value.toLong(0); - os << nikonFocusarea[focusArea] ; + const unsigned long focusArea = value.toLong(0); + if (focusArea >= EXV_COUNTOF(nikonFocusarea)) { + os << "Invalid value"; + } else { + os << nikonFocusarea[focusArea]; + } } if (value.count() >= 2) { os << "; "; diff --git a/test/data/NikonMakerNotePrint0x088_overread b/test/data/NikonMakerNotePrint0x088_overread new file mode 100644 index 00000000..664bdc0c Binary files /dev/null and b/test/data/NikonMakerNotePrint0x088_overread differ diff --git a/tests/bugfixes/github/test_issue_756.py b/tests/bugfixes/github/test_issue_756.py new file mode 100644 index 00000000..464a69ce --- /dev/null +++ b/tests/bugfixes/github/test_issue_756.py @@ -0,0 +1,20 @@ +import system_tests + + +class BufferOverReadInNikon1MakerNotePrint0x0088( + metaclass=system_tests.CaseMeta): + + url = "https://github.com/Exiv2/exiv2/issues/756" + + filename = system_tests.path( + "$data_path/NikonMakerNotePrint0x088_overread" + ) + commands = ["$exiv2 -pt --grep AFFocusPos $filename"] + stdout = [ + """Exif.Nikon1.AFFocusPos Undefined 4 Invalid value; Center +""" + ] + stderr = [""] + retval = [0] + + compare_stderr = system_tests.check_no_ASAN_UBSAN_errors