Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 17 additions & 9 deletions src/canonmn_int.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2690,11 +2690,15 @@ 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::logic_error&) {

@kmilos kmilos Jul 9, 2026

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

std::istringstream seems to throw only std::ios_base::failure, so this should perhaps be the base std::system_error?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't even find any documentation that says what exceptions it might throw! But I did find this, which looks like a simpler solution: https://en.cppreference.com/cpp/io/basic_ios/exceptions. So I think we can just do this and it won't throw any exceptions:

is.exceptions(0);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't even find any documentation that says what exceptions it might throw!

See https://en.cppreference.com/cpp/io/ios_base/failure

I'm fine with either masking or catching std::system_error.

@kmilos kmilos Jul 10, 2026

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Btw https://cplusplus.com/reference/ios/ios/exceptions/ says the mask is 0 by default, so this PR might even be unnecessary on 0.28.x?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just tested it (using #9397) and it looks like std::logic_error is correct. When I tried replacing it with std::system_error the exception didn't get caught.

gdb) run
Starting program: /home/kev/work/exiv2b/build/bin/exiv2 -pa /home/kev/work/exiv2b/test/data/pr_9320.jpg
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/usr/lib/x86_64-linux-gnu/libthread_db.so.1".

Breakpoint 1, Exiv2::Internal::CanonMakerNote::print0x000c (os=..., value=..., exifData=0x555555628420) at /home/kev/work/exiv2b/src/canonmn_int.cpp:2738
2738          return os << value;
(gdb) p e
$1 = (const std::logic_error &) @0x5555556376a0: <incomplete type>
(gdb) 

return os << value;
}
}

std::ostream& CanonMakerNote::print0x000c(std::ostream& os, const Value& value, const ExifData* exifData) {
Expand All @@ -2708,10 +2712,14 @@ 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::logic_error&) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto

return os << value;
}
} else {
return os << value;
}
Expand Down
Loading