Skip to content

parking_lot.c should check for overflow in Windows _PySemaphore_PlatformWait code path #112804

Description

@colesbury

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

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions