Skip to content

Commit

Permalink
[3.13] gh-112804: Clamping timeout value for _PySemaphore_PlatformWait (
Browse files Browse the repository at this point in the history
gh-124914) (gh-124991)

gh-112804: Clamping timeout value for _PySemaphore_PlatformWait (gh-124914)

* gh-112804: Clamping timeout value for _PySemaphore_PlatformWait

* Address code review

* nit
(cherry picked from commit a5fc509)

Co-authored-by: Donghee Na <[email protected]>
  • Loading branch information
miss-islington and corona10 authored Oct 7, 2024
1 parent 8bc8d21 commit 80ba17a
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 80ba17a

Please sign in to comment.