Skip to content

AK: Avoid some overflow conditions in Duration's rational conversions#8936

Merged
Zaggy1024 merged 2 commits intoLadybirdBrowser:masterfrom
Zaggy1024:time-units-overflow-fixes
Apr 16, 2026
Merged

AK: Avoid some overflow conditions in Duration's rational conversions#8936
Zaggy1024 merged 2 commits intoLadybirdBrowser:masterfrom
Zaggy1024:time-units-overflow-fixes

Conversation

@Zaggy1024
Copy link
Copy Markdown
Contributor

There were a few situations where these could allow unchecked overflows. I've fixed those cases and added some tests for them.

Overflow could happen in the multiplication of the remainder seconds
back into time units. Instead, take a remainder of the time units from
the division and use that for the nanoseconds.
With numerators or denominators approaching NumericLimits<u32>::max(),
we could overflow in the sum of the remainder and the rounding
contribution. Instead, divide them separately and sum them afterward.
@Zaggy1024 Zaggy1024 enabled auto-merge (rebase) April 16, 2026 19:06
@Zaggy1024 Zaggy1024 merged commit 3844eda into LadybirdBrowser:master Apr 16, 2026
24 of 27 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.

1 participant