You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
But in case of complex data this can cause errors later.
With the patch C implementation always raises UnpicklingError with relevant message and Python implementation always raises IndexError.
>>> pickle.loads(b'}(NNs.')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'pickle' is not defined
>>> import pickle, pickletools
>>> pickle.loads(b'}(NNs.')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
_pickle.UnpicklingError: unexpected MARK found
>>> pickle.loads(b'](Na.')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
_pickle.UnpicklingError: unexpected MARK found
>>> pickle.loads(b')(.')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
_pickle.UnpicklingError: unexpected MARK found
>>> pickle.loads(b']](a.')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
_pickle.UnpicklingError: unexpected MARK found
>>> pickle._loads(b'}(NNs.')
Traceback (most recent call last):
...
IndexError: list index out of range
>>> pickle._loads(b'](Na.')
Traceback (most recent call last):
...
IndexError: list index out of range
>>> pickle._loads(b')(.')
Traceback (most recent call last):
...
IndexError: pop from empty list
>>> pickle._loads(b']](a.')
Traceback (most recent call last):
...
IndexError: pop from empty list
When pickle stream is unexpectedly ended, different exceptions can be raised. EOFError("Ran out of input") is raised when the stream is unexpectedly ended without the STOP opcode. But it can be raised also when the data for the opcode is incomplete. Other possible exceptions are UnpicklingError, AttributeError and ValueError.
Examples:
>>> pickle.loads(b'L')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
_pickle.UnpicklingError: pickle data was truncated
>>> pickle.loads(b'L10')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
EOFError: Ran out of input
>>> pickle.loads(b'L10L')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: invalid literal for int() with base 10: '10L'
>>> pickle.loads(b"S'abc'")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
_pickle.UnpicklingError: the STRING opcode argument must be quoted
>>> pickle.loads(b'(cbuiltins\nlist')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: Can't get attribute 'lis' on <module 'builtins' (built-in)>
Following patch makes C implementation of unpickler always raise UnpicklingError("pickle data was truncated") if the data for the opcode is truncated (above examples). EOFError("Ran out of input") is raised when the stream is unexpectedly ended without the STOP opcode, as before.
I'm not sure, may be always raise UnpicklingError or EOFError? Or change error message?
Activity
serhiy-storchaka commentedon Nov 29, 2015
This issue is for better detecting and reporting errors in broken pickle data.
python-dev commentedon Nov 29, 2015
New changeset d47e5b162072 by Serhiy Storchaka in branch '3.4':
Issue bpo-25761: Added more test cases for testing unpickling broken data.
https://hg.python.org/cpython/rev/d47e5b162072
New changeset c7e7d77ef8bf by Serhiy Storchaka in branch '2.7':
Issue bpo-25761: Added more test cases for testing unpickling broken data.
https://hg.python.org/cpython/rev/c7e7d77ef8bf
New changeset 4897438543da by Serhiy Storchaka in branch '3.5':
Issue bpo-25761: Added more test cases for testing unpickling broken data.
https://hg.python.org/cpython/rev/4897438543da
New changeset c852c7d8d681 by Serhiy Storchaka in branch 'default':
Issue bpo-25761: Added more test cases for testing unpickling broken data.
https://hg.python.org/cpython/rev/c852c7d8d681
serhiy-storchaka commentedon Nov 29, 2015
Proposed patch allows unpickler to detect errors related to reading a stack behind a mark.
For now Python implementation just pops a sentinel used as a mark. This can cause TypeError, AttributeError or UnpicklingError besides IndexError:
Or can silently expose the mark object:
C implementation just ignores incorrect mark:
But in case of complex data this can cause errors later.
With the patch C implementation always raises UnpicklingError with relevant message and Python implementation always raises IndexError.
python-dev commentedon Dec 6, 2015
New changeset 5c670af0100f by Serhiy Storchaka in branch 'default':
Issue bpo-25761: Improved detecting errors in broken pickle data.
https://hg.python.org/cpython/rev/5c670af0100f
serhiy-storchaka commentedon Dec 6, 2015
When pickle stream is unexpectedly ended, different exceptions can be raised. EOFError("Ran out of input") is raised when the stream is unexpectedly ended without the STOP opcode. But it can be raised also when the data for the opcode is incomplete. Other possible exceptions are UnpicklingError, AttributeError and ValueError.
Examples:
Following patch makes C implementation of unpickler always raise UnpicklingError("pickle data was truncated") if the data for the opcode is truncated (above examples). EOFError("Ran out of input") is raised when the stream is unexpectedly ended without the STOP opcode, as before.
I'm not sure, may be always raise UnpicklingError or EOFError? Or change error message?
python-dev commentedon Dec 7, 2015
New changeset 001514146c21 by Serhiy Storchaka in branch 'default':
Issue bpo-25761: Fixed reference leak added in previous changeset (5c670af0100f).
https://hg.python.org/cpython/rev/001514146c21
python-dev commentedon Sep 6, 2016
New changeset 231f578dfd3d by Serhiy Storchaka in branch 'default':
Issue bpo-25761: Improved error reporting about truncated pickle data in
https://hg.python.org/cpython/rev/231f578dfd3d