Skip to content

catch stoul exceptions in CanonMakerNote print0x000a/print0x000c#9320

Open
netliomax25-code wants to merge 3 commits into
Exiv2:mainfrom
netliomax25-code:canon-print-stoul-catch
Open

catch stoul exceptions in CanonMakerNote print0x000a/print0x000c#9320
netliomax25-code wants to merge 3 commits into
Exiv2:mainfrom
netliomax25-code:canon-print-stoul-catch

Conversation

@netliomax25-code

Copy link
Copy Markdown
Contributor

print0x000a and print0x000c call std::stoul(value.toString()), but the stored type of Canon tags 0x000a and 0x000c is not enforced during parsing, so a crafted makernote can hand them a non-numeric ASCII value. stoul then throws std::invalid_argument, which Exifdatum::write does not catch (it only guards std::out_of_range), so it escapes during -pa printing. Catch both and fall back to the raw value, like the existing path in print0x000c.

@kevinbackhouse

Copy link
Copy Markdown
Collaborator

@mergify backport 0.28.x 0.29.x

@mergify

mergify Bot commented Jun 21, 2026

Copy link
Copy Markdown
Contributor

backport 0.28.x 0.29.x

🟠 Waiting for conditions to match

Details
  • merged [📌 backport requirement]

Comment thread src/canonmn_int.cpp Outdated
Comment on lines +2720 to +2723
} catch (const std::invalid_argument&) {
return os << value;
} catch (const std::out_of_range&) {
return os << value;

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.

Suggested change
} catch (const std::invalid_argument&) {
return os << value;
} catch (const std::out_of_range&) {
return os << value;
} catch (const std::logic_error&) {
return os << value;

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good catch, both derive from std::logic_error so one catch covers them. Switched both functions over and pushed.

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.

You used std::logic_error in #9321, so why not here? It makes me think that this is AI-generated code.

Comment thread src/canonmn_int.cpp Outdated
Comment on lines +2739 to +2742
} catch (const std::invalid_argument&) {
return os << value;
} catch (const std::out_of_range&) {
return os << value;

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.

Suggested change
} catch (const std::invalid_argument&) {
return os << value;
} catch (const std::out_of_range&) {
return os << value;
} catch (const std::logic_error&) {
return os << value;

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Same here, collapsed to std::logic_error in print0x000c too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants