Skip to content

Commit

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

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

* pythongh-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.