Serhiy Storchaka added the comment: 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? ---------- Added file: http://bugs.python.org/file41257/unpickling_eof_errors.patch _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue25761> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com