bpo-38876: Raise pickle.UnpicklingError when loading an item from memo for invalid input#17335
Merged
miss-islington merged 1 commit intopython:masterfrom Nov 24, 2019
Conversation
avassalotti
reviewed
Nov 22, 2019
Modules/_pickle.c
Outdated
Member
There was a problem hiding this comment.
Can you show the invalid memo key in the exception message?
Contributor
Author
There was a problem hiding this comment.
Sure thing, let me know if the new changes make sense.
…o for invalid input The previous code was raising a `KeyError` for both the Python and C implementation. This was caused by the specified index of an invalid input which did not exist in the memo structure, where the pickle stores what objects it has seen. The malformed input would have caused either a `BINGET` or `LONG_BINGET` load from the memo, leading to a `KeyError` as the determined index was bogus.
15a30cc to
f8e15c1
Compare
Contributor
Author
|
Thank you for the review @avassalotti ! Let me know if the latest patch make sense. |
avassalotti
approved these changes
Nov 23, 2019
jacobneiltaylor
pushed a commit
to jacobneiltaylor/cpython
that referenced
this pull request
Dec 5, 2019
…o for invalid input (pythonGH-17335) The previous code was raising a `KeyError` for both the Python and C implementation. This was caused by the specified index of an invalid input which did not exist in the memo structure, where the pickle stores what objects it has seen. The malformed input would have caused either a `BINGET` or `LONG_BINGET` load from the memo, leading to a `KeyError` as the determined index was bogus. https://bugs.python.org/issue38876 https://bugs.python.org/issue38876
| PyErr_SetObject(PyExc_KeyError, key); | ||
| if (!PyErr_Occurred()) { | ||
| PickleState *st = _Pickle_GetGlobalState(); | ||
| PyErr_Format(st->UnpicklingError, "Memo value not found at index %ld", idx); |
Contributor
There was a problem hiding this comment.
%zd should be used with Py_ssize_t, not %ld.
| if (key != NULL) { | ||
| PyErr_SetObject(PyExc_KeyError, key); | ||
| PickleState *st = _Pickle_GetGlobalState(); | ||
| PyErr_Format(st->UnpicklingError, "Memo value not found at index %ld", idx); |
| if (key != NULL) { | ||
| PyErr_SetObject(PyExc_KeyError, key); | ||
| PickleState *st = _Pickle_GetGlobalState(); | ||
| PyErr_Format(st->UnpicklingError, "Memo value not found at index %ld", idx); |
shihai1991
pushed a commit
to shihai1991/cpython
that referenced
this pull request
Jan 31, 2020
…o for invalid input (pythonGH-17335) The previous code was raising a `KeyError` for both the Python and C implementation. This was caused by the specified index of an invalid input which did not exist in the memo structure, where the pickle stores what objects it has seen. The malformed input would have caused either a `BINGET` or `LONG_BINGET` load from the memo, leading to a `KeyError` as the determined index was bogus. https://bugs.python.org/issue38876 https://bugs.python.org/issue38876
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The previous code was raising a
KeyErrorfor both the Python and C implementation.This was caused by the specified index of an invalid input which did not exist
in the memo structure, where the pickle stores what objects it has seen.
The malformed input would have caused either a
BINGETorLONG_BINGETloadfrom the memo, leading to a
KeyErroras the determined index was bogus.https://bugs.python.org/issue38876
https://bugs.python.org/issue38876
Automerge-Triggered-By: @avassalotti