-
-
Notifications
You must be signed in to change notification settings - Fork 32.1k
bpo-34656: Avoid relying on signed overflow in _pickle memos. #9261
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
Conversation
ea95daa
to
59c974e
Compare
Modules/_pickle.c
Outdated
@@ -7061,7 +7057,7 @@ Unpickler_set_memo(UnpicklerObject *self, PyObject *obj) | |||
error: | |||
if (new_memo_size) { | |||
i = new_memo_size; |
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.
It looks like this line is redundant now.
Modules/_pickle.c
Outdated
Py_ssize_t to_process; | ||
|
||
assert(min_size > 0); | ||
|
||
/* Find the smallest valid table size >= min_size. */ | ||
while (new_size < min_size && new_size > 0) | ||
while (new_size < min_size) |
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.
Wouldn't this cause an infinite loop if min_size
> PY_SSIZE_T_MAX
?
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.
Yes, I will fix.
Modules/_pickle.c
Outdated
@@ -909,7 +909,8 @@ PyMemoTable_Set(PyMemoTable *self, PyObject *key, Py_ssize_t value) | |||
* Very large memo tables (over 50K items) use doubling instead. | |||
* This may help applications with severe memory constraints. | |||
*/ | |||
if (!(self->mt_used * 3 >= (self->mt_mask + 1) * 2)) | |||
size_t triple_used = self->mt_used * 3; | |||
if (triple_used > self->mt_used && triple_used < self->mt_allocated * 2) |
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.
triple_used > self->mt_used
Is this a wrapping/overflow detection?
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.
yes
7975314
to
d8b389b
Compare
Thanks @benjaminp for the PR 🌮🎉.. I'm working now to backport this PR to: 3.6, 3.7. |
…ythonGH-9261) (cherry picked from commit a4ae828) Co-authored-by: Benjamin Peterson <benjamin@python.org>
GH-9465 is a backport of this pull request to the 3.7 branch. |
…ythonGH-9261) (cherry picked from commit a4ae828) Co-authored-by: Benjamin Peterson <benjamin@python.org>
GH-9466 is a backport of this pull request to the 3.6 branch. |
https://bugs.python.org/issue1621