https://github.com/python/cpython/commit/a5fc50994a3fae46d0c3d496c4e1d5e00548a1b8
commit: a5fc50994a3fae46d0c3d496c4e1d5e00548a1b8
branch: main
author: Donghee Na <[email protected]>
committer: corona10 <[email protected]>
date: 2024-10-05T11:27:32+09:00
summary:
gh-112804: Clamping timeout value for _PySemaphore_PlatformWait (gh-124914)
* gh-112804: Clamping timeout value for _PySemaphore_PlatformWait
* Address code review
* nit
files:
M Python/parking_lot.c
diff --git a/Python/parking_lot.c b/Python/parking_lot.c
index 841b1d71ea16cb..a7e9760e35d87a 100644
--- a/Python/parking_lot.c
+++ b/Python/parking_lot.c
@@ -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) {
_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-checkins.python.org/
Member address: [email protected]