bpo-34656: Avoid relying on signed overflow in _pickle memos. #9261
Conversation
Modules/_pickle.c
Outdated
| @@ -7061,7 +7057,7 @@ Unpickler_set_memo(UnpicklerObject *self, PyObject *obj) | |||
| error: | |||
| if (new_memo_size) { | |||
| i = new_memo_size; | |||
sir-sigurd
Sep 14, 2018
Contributor
It looks like this line is redundant now.
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) |
serhiy-storchaka
Sep 15, 2018
Member
Wouldn't this cause an infinite loop if min_size > PY_SSIZE_T_MAX?
Wouldn't this cause an infinite loop if min_size > PY_SSIZE_T_MAX?
benjaminp
Sep 15, 2018
Author
Contributor
Yes, I will fix.
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) | |||
sir-sigurd
Sep 15, 2018
Contributor
triple_used > self->mt_used
Is this a wrapping/overflow detection?
triple_used > self->mt_used
Is this a wrapping/overflow detection?
benjaminp
Sep 15, 2018
Author
Contributor
yes
yes
a4ae828
into
master
7 of 9 checks passed
7 of 9 checks passed
bedevere/news
"skip news" label found
|
Thanks @benjaminp for the PR |
miss-islington
added a commit
to miss-islington/cpython
that referenced
this pull request
Sep 21, 2018
…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. |
miss-islington
added a commit
to miss-islington/cpython
that referenced
this pull request
Sep 21, 2018
…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. |
miss-islington
added a commit
that referenced
this pull request
Sep 21, 2018
miss-islington
added a commit
that referenced
this pull request
Sep 21, 2018
yahya-abou-imran
added a commit
to yahya-abou-imran/cpython
that referenced
this pull request
Nov 2, 2018
vstinner
added a commit
to vstinner/cpython
that referenced
this pull request
Feb 15, 2019
…ythonGH-9261) (cherry picked from commit a4ae828)
vstinner
added a commit
to vstinner/cpython
that referenced
this pull request
Feb 15, 2019
…ythonGH-9261) (cherry picked from commit a4ae828)
larryhastings
added a commit
that referenced
this pull request
Feb 25, 2019
larryhastings
added a commit
that referenced
this pull request
Feb 26, 2019
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
https://bugs.python.org/issue1621