Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
colesbury opened this issue Dec 6, 2023 · 2 comments
Labels
3.13 bugs and security fixes OS-windows topic-free-threading type-bug An unexpected behavior, bug, or error

Comments

@colesbury
Copy link
Contributor

colesbury commented Dec 6, 2023

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.

static int
_PySemaphore_PlatformWait(_PySemaphore *sema, _PyTime_t timeout)
{
int res;
#if defined(MS_WINDOWS)
DWORD wait;
DWORD millis = 0;
if (timeout < 0) {
millis = INFINITE;
}
else {
millis = (DWORD) (timeout / 1000000);
}

Noticed by @vstinner in #112733 (review)

Linked PRs

@colesbury colesbury added type-bug An unexpected behavior, bug, or error 3.13 bugs and security fixes topic-free-threading labels Dec 6, 2023
corona10 added a commit that referenced this issue Oct 5, 2024
…24914)

* gh-112804: Clamping timeout value for _PySemaphore_PlatformWait

* Address code review

* nit
miss-islington pushed a commit to miss-islington/cpython that referenced this issue Oct 5, 2024
…pythongh-124914)

* pythongh-112804: Clamping timeout value for _PySemaphore_PlatformWait

* Address code review

* nit
(cherry picked from commit a5fc509)

Co-authored-by: Donghee Na <[email protected]>
corona10 added a commit to miss-islington/cpython that referenced this issue Oct 7, 2024
…pythongh-124914)

* pythongh-112804: Clamping timeout value for _PySemaphore_PlatformWait

* Address code review

* nit
(cherry picked from commit a5fc509)

Co-authored-by: Donghee Na <[email protected]>
corona10 added a commit that referenced this issue Oct 7, 2024
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 a5fc509)

Co-authored-by: Donghee Na <[email protected]>
@corona10
Copy link
Member

corona10 commented Oct 8, 2024

@colesbury, I am closing the issue if we need to reopen it. please let me know.

@corona10 corona10 closed this as completed Oct 8, 2024
@colesbury
Copy link
Contributor Author

Thanks for fixing this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.13 bugs and security fixes OS-windows topic-free-threading type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

3 participants