diff --git a/src/tiffcomposite_int.cpp b/src/tiffcomposite_int.cpp index 6da7a964d2..8890ec47c8 100644 --- a/src/tiffcomposite_int.cpp +++ b/src/tiffcomposite_int.cpp @@ -1207,7 +1207,12 @@ namespace Exiv2 { valueIdx, dataIdx, imageIdx); - assert(len <= 4); +#ifndef SUPPRESS_WARNINGS + if (len > 4) { + EXV_ERROR << "Unexpected length in TiffDirectory::writeDirEntry(): len == " + << len << ".\n"; + } +#endif if (len < 4) { memset(buf, 0x0, 4); ioWrapper.write(buf, 4 - len); diff --git a/test/data/issue_1845_poc.jp2 b/test/data/issue_1845_poc.jp2 new file mode 100644 index 0000000000..035d629621 Binary files /dev/null and b/test/data/issue_1845_poc.jp2 differ diff --git a/tests/bugfixes/github/test_issue_1845.py b/tests/bugfixes/github/test_issue_1845.py new file mode 100644 index 0000000000..6332ab18fc --- /dev/null +++ b/tests/bugfixes/github/test_issue_1845.py @@ -0,0 +1,17 @@ +# -*- coding: utf-8 -*- + +from system_tests import CaseMeta, CopyTmpFiles, path +@CopyTmpFiles("$data_path/issue_1845_poc.jp2") + +class TiffDirectoryWriteDirEntryAssert(metaclass=CaseMeta): + """ + Regression test for the bug described in: + https://github.com/Exiv2/exiv2/issues/1845 + """ + url = "https://github.com/Exiv2/exiv2/issues/1845" + + filename = path("$tmp_path/issue_1845_poc.jp2") + commands = ["$exiv2 -q -D +1 ad $filename"] + stderr = [""] + stdout = [""] + retval = [0]