-
-
Notifications
You must be signed in to change notification settings - Fork 33.6k
gh-128965: pickle load_build function checks if state is None, not False
#128966
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
base: main
Are you sure you want to change the base?
Conversation
picnixz
left a comment
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.
Can we have tests that check this code path? Namely check that non-dict objects raise a TypeError and that falsey dicts do not raise exceptions? In addition, we need a NEWS entry for the bugfix, e.g:
Fix :meth:`!pickle._Pickler.load_build` for non-dictionary states.(My NEWS entry is definitely poorly worded but I don't have a better suggestion for now. Maybe you can come up with a better formulation).
Co-authored-by: Bénédikt Tran <[email protected]>
Added 6 tests where the `state` is falsey but not None, and the `inst` value is invalid - these should throw an AttributeError because the `__dict__` attribute doesn't exist for `inst`. In `pickle.py`, if `state` is falsey but not None code is never run to check that `inst` is a valid object (but it does happen in the C accelerator).
|
@picnixz I went ahead and added some tests and a NEWS entry. The problem here isn't that |
|
Okay, I'm not sure how to specify in the test that I want the Python version of the |
|
Okay I now understand that |
Inside of the
load_build()function for pickle'sBUILDopcode, the C accelerator at one point checks ifstateisPy_None, while the Python version only checksif state.cpython/Modules/_pickle.c
Line 6638 in 34ded1a
cpython/Lib/pickle.py
Line 1765 in 34ded1a
This means if
stateis something like an empty dictionary or tuple, the code block under theifstatement WILL be run in_pickle.c, but NOT inpickle.py.As an example, the bytestream
b']]b.'has the following disassembly:This will do nothing in
pickle.pybut error out in_pickle.cwith the messagestate is not a dictionary. The easy solution is to changeif statetoif state != None, and it shouldn't break any existing functionality. I've attached a pull request.load_buildfunction checks ifstateis None, not False #128965