Bug report
The cast in millis = (DWORD) (timeout / 1000000); may overflow because DWORD is an unsigned 32-bit integer and timeout is a 64-bit integer. We should clamp the result if the cast would overflow.
| staticint |
| _PySemaphore_PlatformWait(_PySemaphore*sema, _PyTime_ttimeout) |
| { |
| intres; |
| #if defined(MS_WINDOWS) |
| DWORDwait; |
| DWORDmillis=0; |
| if (timeout<0) { |
| millis=INFINITE; |
| } |
| else { |
| millis= (DWORD) (timeout / 1000000); |
| } |
Noticed by @vstinner in #112733 (review)
Linked PRs
Bug report
The cast in
millis = (DWORD) (timeout / 1000000);may overflow becauseDWORDis an unsigned 32-bit integer andtimeoutis a 64-bit integer. We should clamp the result if the cast would overflow.cpython/Python/parking_lot.c
Lines 93 to 105 in cc7e45c
Noticed by @vstinner in #112733 (review)
Linked PRs