Skip to content

Fix overflow in Multi::timeout_i32 - #663

Merged
sagebind merged 2 commits into
sagebind:mainfrom
rizwan3659:fix-timeout-i32-overflow
Oct 10, 2026
Merged

sagebind merged 2 commits into
sagebind:mainfrom
rizwan3659:fix-timeout-i32-overflow

Conversation

@rizwan3659

@rizwan3659 rizwan3659 commented Sep 10, 2026 •

Copy link
Copy Markdown
Contributor

timeout_i32 has an off-by-one in its clamp check. It compares the whole
seconds against i32::MAX / 1000 using >, so a duration of exactly
2147483 seconds skips the clamp and goes into the arithmetic branch. If the
sub-second part is 648ms or more, secs * 1000 + millis ends up past
i32::MAX.

In debug builds this panics with "attempt to add with overflow". In release
builds it wraps around to a negative number instead, and libcurl's
multi_wait() rejects negative timeouts, so Multi::wait() and
Multi::poll() return CURLM_BAD_FUNCTION_ARGUMENT instead of waiting.

This changes it to work out the timeout in milliseconds first and then clamp
it to i32::MAX, so there's no intermediate value that can overflow. I also
added a unit test for the boundary values and for Duration::MAX.

Fixes #659

@rizwan3659
rizwan3659 force-pushed the fix-timeout-i32-overflow branch from 30e397e to ec987c0 Compare September 10, 2026 14:14
@rizwan3659 rizwan3659 changed the title Fix overlow in Multi::timeout_i32 Fix overflow in Multi::timeout_i32 Sep 10, 2026
@sagebind
sagebind merged commit 2fb602b into sagebind:main Oct 10, 2026
13 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.

Multi::wait() and Multi::poll() panic on valid Duration input due to integer overflow in timeout_i32

2 participants