Skip to content

Commit

Permalink
Merge pull request #1767 from kevinbackhouse/fix-issue-1763
Browse files Browse the repository at this point in the history
Fix null iterator deref in printCsLensTypeByMetadata
  • Loading branch information
kevinbackhouse authored Jul 9, 2021
2 parents c7757d7 + 033175e commit 9284b58
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/canonmn_int.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2750,6 +2750,7 @@ namespace Exiv2 {
if (pos == metadata->end() || pos->value().count() < 3 || pos->value().typeId() != unsignedShort ||
pos->value().toFloat(2) == 0.0F) {
os << "Unknown Lens (" << lensType << ")";
return os;
}

int const exifFlMin = static_cast<int>(static_cast<float>(pos->value().toLong(1)) / pos->value().toFloat(2));
Expand All @@ -2759,6 +2760,7 @@ namespace Exiv2 {
pos = metadata->findKey(aperKey);
if (pos == metadata->end() || pos->value().count() != 1 || pos->value().typeId() != unsignedShort) {
os << "Unknown Lens (" << lensType << ")";
return os;
}

auto exifAperMax = fnumber(canonEv(static_cast<int16_t>(pos->value().toLong(0))));
Expand Down
Binary file added test/data/issue_1763_poc.exv
Binary file not shown.
20 changes: 20 additions & 0 deletions tests/bugfixes/github/test_issue_1763.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# -*- coding: utf-8 -*-

from system_tests import CaseMeta, path

class CanonPrintCsLensTypeByMetadataNullIteratorDeref(metaclass=CaseMeta):
"""
Regression test for the bug described in:
https://github.com/Exiv2/exiv2/issues/1763
"""
url = "https://github.com/Exiv2/exiv2/issues/1763"

filename = path("$data_path/issue_1763_poc.exv")
commands = ["$exiv2 -Pt $filename"]

stderr = [""]
retval = [0]

def compare_stdout(self, i, command, got_stdout, expected_stdout):
# Check that it printed "Bad value" for the date.
self.assertIn("Unknown Lens (254)", got_stdout)

0 comments on commit 9284b58

Please sign in to comment.