Skip to content

Commit 6cc71a5

Browse files
committed
pythongh-112804: Clamping timeout value for _PySemaphore_PlatformWait
1 parent 7bdfabe commit 6cc71a5

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

Python/parking_lot.c

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

0 commit comments

Comments
 (0)