[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 a5fc50994a)

Co-authored-by: Donghee Na <donghee.na@python.org>
This commit is contained in:
Miss Islington (bot) 2024-10-07 18:53:32 +02:00 committed by GitHub
parent 8bc8d21ac7
commit 80ba17a3dd
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 8 additions and 1 deletions

View File

@ -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) {