Skip to content

Commit

Permalink
gh-112804: Clamping timeout value for _PySemaphore_PlatformWait (gh-1…
Browse files Browse the repository at this point in the history
…24914)

* gh-112804: Clamping timeout value for _PySemaphore_PlatformWait

* Address code review

* nit
  • Loading branch information
corona10 authored Oct 5, 2024
1 parent adfe765 commit a5fc509
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion Python/parking_lot.c
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,14 @@ _PySemaphore_PlatformWait(_PySemaphore *sema, PyTime_t timeout)
millis = INFINITE;
}
else {
millis = (DWORD) (timeout / 1000000);
PyTime_t div = _PyTime_AsMilliseconds(timeout, _PyTime_ROUND_TIMEOUT);
// Prevent overflow with clamping the result
if ((PyTime_t)PY_DWORD_MAX < div) {
millis = PY_DWORD_MAX;
}
else {
millis = (DWORD) div;
}
}
wait = WaitForSingleObjectEx(sema->platform_sem, millis, FALSE);
if (wait == WAIT_OBJECT_0) {
Expand Down

0 comments on commit a5fc509

Please sign in to comment.