Skip to content

canonmn_int: round converted focal lengths - #9475

Merged
kevinbackhouse merged 1 commit into
Exiv2:mainfrom
geri1701:fix-i686-lens-rounding
Sep 4, 2026
Merged

canonmn_int: round converted focal lengths#9475
kevinbackhouse merged 1 commit into
Exiv2:mainfrom
geri1701:fix-i686-lens-rounding

Conversation

@geri1701

@geri1701 geri1701 commented Sep 3, 2026

Copy link
Copy Markdown

On i686, x87 excess floating-point precision can make products such as 100.0F * 1.4F slightly lower than 140. Converting that value directly to int truncates it to 139, so teleconverter lens entries do not match the focal lengths decoded from metadata.

This rounds the focal lengths after applying the teleconverter factor and before converting them to int. The existing lens tests cover the affected cases.

Verification:

  • i686: all 6 CTest suites pass (baseline: 28 lens-test failures)
  • x86_64: all 6 CTest suites pass

On i686, excess floating-point precision can make products such as
100.0F * 1.4F slightly lower than 140. Converting that value directly
to int truncates it to 139, so teleconverter lenses do not match their
EXIF focal lengths.

Round the products before converting them to int to make lens matching
independent of excess floating-point precision.

@kevinbackhouse kevinbackhouse left a comment

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.

Thanks! This is an improvement.

By the way, do you know whether there's a possibility that the number could be too big, causing the static_cast<int> to overflow? If so, somebody is inevitably going to send us a vulnerability report about it so it might be good to fix it proactively. I recently wrote some code to do a cast with overflow checking in #9433.

@mergify

mergify Bot commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

Tick the box to add this pull request to the merge queue (same as @mergifyio queue).

  • Queue this pull request

@kmilos kmilos added this to the v0.29.0 milestone Sep 3, 2026
@geri1701

geri1701 commented Sep 3, 2026

Copy link
Copy Markdown
Author

By the way, do you know whether there's a possibility that the number could be too big, causing the static_cast<int> to overflow? If so, somebody is inevitably going to send us a vulnerability report about it so it might be good to fix it proactively. I recently wrote some code to do a cast with overflow checking in #9433.

The values passed to std::lround here come from the built-in canonCsLensType labels rather than metadata. Across the current 533 entries, the largest focal-length × teleconverter value is 2400, so the conversion is safely within the range of int.

@kevinbackhouse
kevinbackhouse merged commit fb0650a into Exiv2:main Sep 4, 2026
318 of 335 checks passed
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.

3 participants