-
-
Notifications
You must be signed in to change notification settings - Fork 32.2k
bpo-33632: Avoid signed integer overflow in the _thread module #12729
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
bpo-33632: Avoid signed integer overflow in the _thread module #12729
Conversation
Co-Authored-By: Martin Panter <vadmium+py@gmail.com>
@ZackerySpytz The approach looks good to me, but I think it would be good to add a test here. Is I also think it might be worth adding some of the details of exactly what user-facing behaviors will change with this patch to the changelog. "Avoid signed integer overflow" doesn't mean too much to me, out of context, and the BPO report is not much more detailed. |
r = PY_LOCK_FAILURE; | ||
} | ||
else { | ||
timeout -= elapsed; | ||
starttime += elapsed; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure that this part is really needed. I would prefer to leave starttime and timeout unchanged.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you, @vstinner, for your review.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The original code also updates timeout every time it is interrupted. If you don’t adjust the timeout, I think the overall timeout could be too long. I expect you would be able to test this by installing a Python signal handler and sending signals while acquire or whatever method is running.
Perhaps you would prefer to calculate (overall) timeout − (overall) elapsed and pass that to PyThread_acquire_lock_timed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
starttime += elapsed
will cause starttime
overflow. Because starttime
is closer to _PyTime_GetMonotonicClock() + timeout
by accumulating, and _PyTime_GetMonotonicClock() + timeout
may overflow.
I think the else
block is not needed.
To clarify the changelog, you could say it is a timeout value that causes the overflow, and figure out what APIs are affected. I suspect some acquire method(s) of lock object(s), such as threading.Lock.acquire, but someone with an up-to-date copy of the code should confirm. |
@ZackerySpytz, please take a look at the code review comments. Thanks! |
@ZackerySpytz Are you interested in continuing to work on this PR? |
This was fixed in #28674, as mentioned on the bpo. |
Co-Authored-By: Martin Panter vadmium+py@gmail.com
https://bugs.python.org/issue33632