[New-bugs-announce] [issue25248] Discrepancy in unpickling integers with protocol 0
Serhiy Storchaka
report at bugs.python.org
Sun Sep 27 17:23:56 CEST 2015
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 <report at bugs.python.org>
<http://bugs.python.org/issue25248>
_______________________________________
More information about the New-bugs-announce
mailing list