This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author serhiy.storchaka
Recipients alexandre.vassalotti, pitrou, python-dev, serhiy.storchaka
Date 2015-12-06.21:36:36
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1449437797.08.0.299665439604.issue25761@psf.upfronthosting.co.za>
In-reply-to
Content
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?
History
Date User Action Args
2015-12-06 21:36:37serhiy.storchakasetrecipients: + serhiy.storchaka, pitrou, alexandre.vassalotti, python-dev
2015-12-06 21:36:37serhiy.storchakasetmessageid: <1449437797.08.0.299665439604.issue25761@psf.upfronthosting.co.za>
2015-12-06 21:36:37serhiy.storchakalinkissue25761 messages
2015-12-06 21:36:36serhiy.storchakacreate