New submission from Serhiy Storchaka: There are discrepancies between Python 2 and Python 3, Python and C implementations, INT and LONG opcodes when unpickle integer with protocol 0.
Python 2.7: >>> import pickle, cPickle >>> pickle.loads(b'I010\n.') 10 >>> cPickle.loads(b'I010\n.') 8 >>> pickle.loads(b'L010\n.') 8L >>> cPickle.loads(b'L010\n.') 8L Python 3.6: >>> import pickle >>> pickle.loads(b'I010\n.') 8 >>> pickle._loads(b'I010\n.') Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/home/serhiy/py/cpython/Lib/pickle.py", line 1557, in _loads encoding=encoding, errors=errors).load() File "/home/serhiy/py/cpython/Lib/pickle.py", line 1039, in load dispatch[key[0]](self) File "/home/serhiy/py/cpython/Lib/pickle.py", line 1106, in load_int val = int(data, 0) ValueError: invalid literal for int() with base 0: b'010\n' >>> pickle.loads(b'L010\n.') Traceback (most recent call last): File "<stdin>", line 1, in <module> ValueError: invalid literal for int() with base 0: '010\n' >>> pickle._loads(b'L010\n.') Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/home/serhiy/py/cpython/Lib/pickle.py", line 1557, in _loads encoding=encoding, errors=errors).load() File "/home/serhiy/py/cpython/Lib/pickle.py", line 1039, in load dispatch[key[0]](self) File "/home/serhiy/py/cpython/Lib/pickle.py", line 1126, in load_long self.append(int(val, 0)) ValueError: invalid literal for int() with base 0: b'010' ---------- components: Extension Modules, Library (Lib) messages: 251705 nosy: alexandre.vassalotti, pitrou, serhiy.storchaka priority: normal severity: normal status: open title: Discrepancy in unpickling integers with protocol 0 type: behavior versions: Python 2.7, Python 3.4, Python 3.5, Python 3.6 _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue25248> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com