Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

drivers: video: video_common: refactor video_closest_frmival_stepwise() #85697

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

josuah
Copy link
Collaborator

@josuah josuah commented Feb 13, 2025

Avoid an integer overflow by reducing the precision until the result is checked to fit in 32-bit. This is possible by simplifying fractions by 2, which should not affect the result significantly as this is only done when the values are extremely large (too large to fit 32-bit int).

Also adding a test case that would overflow without proper handling.

Fixes:


/* Loose precision until landing within 32-bit range */
while (numerator_min > UINT32_MAX || numerator_step > UINT32_MAX ||
denominator >UINT32_MAX) {
Copy link
Member

Choose a reason for hiding this comment

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

^^ missing space, see the compliance check

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

You are right... Should be fixed now!

Avoid an integer overflow by dividing the numerator and denominator
by two (dropping one bit of precision), which preserve the ratio.
Result still accurate, as only done on values larger than UINT32_MAX.
fixes CID-444385, CID-444388 and CID-444389

Signed-off-by: Josuah Demangeon <[email protected]>
@josuah josuah force-pushed the pr-fix-video-common branch from 7f723af to eaee9f1 Compare February 13, 2025 12:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants