Skip to content

Commit 80ba17a

Browse files
[3.13] gh-112804: Clamping timeout value for _PySemaphore_PlatformWait (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]>
1 parent 8bc8d21 commit 80ba17a

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

Python/parking_lot.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,14 @@ _PySemaphore_PlatformWait(_PySemaphore *sema, PyTime_t timeout)
102102
millis = INFINITE;
103103
}
104104
else {
105-
millis = (DWORD) (timeout / 1000000);
105+
PyTime_t div = _PyTime_AsMilliseconds(timeout, _PyTime_ROUND_TIMEOUT);
106+
// Prevent overflow with clamping the result
107+
if ((PyTime_t)PY_DWORD_MAX < div) {
108+
millis = PY_DWORD_MAX;
109+
}
110+
else {
111+
millis = (DWORD) div;
112+
}
106113
}
107114
wait = WaitForSingleObjectEx(sema->platform_sem, millis, FALSE);
108115
if (wait == WAIT_OBJECT_0) {

0 commit comments

Comments
 (0)