From 200e45320e1664800408a8f796e507523be289df Mon Sep 17 00:00:00 2001 From: netliomax25-code Date: Mon, 1 Jun 2026 23:49:19 +0530 Subject: [PATCH 1/2] catch stoul exceptions in CanonMakerNote print0x000a/print0x000c --- src/canonmn_int.cpp | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/src/canonmn_int.cpp b/src/canonmn_int.cpp index b556e27351..797f3ce288 100644 --- a/src/canonmn_int.cpp +++ b/src/canonmn_int.cpp @@ -2690,11 +2690,17 @@ std::ostream& CanonMakerNote::print0x0008(std::ostream& os, const Value& value, } std::ostream& CanonMakerNote::print0x000a(std::ostream& os, const Value& value, const ExifData*) { - std::istringstream is(value.toString()); - uint32_t l = 0; - is >> l; - return os << std::setw(4) << std::setfill('0') << std::hex << ((l & 0xffff0000) >> 16) << std::setw(5) - << std::setfill('0') << std::dec << (l & 0x0000ffff); + try { + std::istringstream is(value.toString()); + uint32_t l = 0; + is >> l; + return os << std::setw(4) << std::setfill('0') << std::hex << ((l & 0xffff0000) >> 16) << std::setw(5) + << std::setfill('0') << std::dec << (l & 0x0000ffff); + } catch (const std::invalid_argument&) { + return os << value; + } catch (const std::out_of_range&) { + return os << value; + } } std::ostream& CanonMakerNote::print0x000c(std::ostream& os, const Value& value, const ExifData* exifData) { @@ -2708,10 +2714,16 @@ std::ostream& CanonMakerNote::print0x000c(std::ostream& os, const Value& value, auto pos = exifData->findKey(key); // if model is EOS D30 if (pos != exifData->end() && pos->value().count() == 1 && pos->value().toInt64() == 0x01140000) { - uint32_t l = 0; - is >> l; - return os << std::setw(4) << std::setfill('0') << std::hex << ((l & 0xffff0000) >> 16) << std::setw(5) - << std::setfill('0') << std::dec << (l & 0x0000ffff); + try { + uint32_t l = 0; + is >> l; + return os << std::setw(4) << std::setfill('0') << std::hex << ((l & 0xffff0000) >> 16) << std::setw(5) + << std::setfill('0') << std::dec << (l & 0x0000ffff); + } catch (const std::invalid_argument&) { + return os << value; + } catch (const std::out_of_range&) { + return os << value; + } } else { return os << value; } From 5502e983071de6e7df054342b744c2f1a0b505b0 Mon Sep 17 00:00:00 2001 From: netliomax25-code Date: Mon, 22 Jun 2026 16:52:04 +0530 Subject: [PATCH 2/2] catch std::logic_error to cover both stoul failure modes --- src/canonmn_int.cpp | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/canonmn_int.cpp b/src/canonmn_int.cpp index 797f3ce288..e2d27985af 100644 --- a/src/canonmn_int.cpp +++ b/src/canonmn_int.cpp @@ -2696,9 +2696,7 @@ std::ostream& CanonMakerNote::print0x000a(std::ostream& os, const Value& value, is >> l; return os << std::setw(4) << std::setfill('0') << std::hex << ((l & 0xffff0000) >> 16) << std::setw(5) << std::setfill('0') << std::dec << (l & 0x0000ffff); - } catch (const std::invalid_argument&) { - return os << value; - } catch (const std::out_of_range&) { + } catch (const std::logic_error&) { return os << value; } } @@ -2719,9 +2717,7 @@ std::ostream& CanonMakerNote::print0x000c(std::ostream& os, const Value& value, is >> l; return os << std::setw(4) << std::setfill('0') << std::hex << ((l & 0xffff0000) >> 16) << std::setw(5) << std::setfill('0') << std::dec << (l & 0x0000ffff); - } catch (const std::invalid_argument&) { - return os << value; - } catch (const std::out_of_range&) { + } catch (const std::logic_error&) { return os << value; } } else {