[Python-bugs-list] [ python-Bugs-504723 ] Bad exceptions from pickle
noreply@sourceforge.net
noreply@sourceforge.net
Wed, 16 Jan 2002 19:55:23 -0800
Bugs item #504723, was opened at 2002-01-16 19:55
You can respond by visiting:
http://sourceforge.net/tracker/?func=detail&atid=105470&aid=504723&group_id=5470
Category: Python Library
Group: Python 2.2
Status: Open
Resolution: None
Priority: 5
Submitted By: Bob Alexander (bobalex)
Assigned to: Nobody/Anonymous (nobody)
Summary: Bad exceptions from pickle
Initial Comment:
Here is an annotated session that shows some incorrect
exceptions raised with bad input. I'm assuming that it
is intended that when attempting to load a pickle file,
we should only have to check for UnpicklingError, not
for several other possible exceptions.
>>> import sys
>>> sys.version
'2.2 (#1, Dec 26 2001, 16:14:13) \n[GCC 2.96 20000731
(Mandrake Linux 8.1 2.96-0.62mdk)]'
Problem 1: Attempting to load an empty file produces an
EOFError exception, but should probably produce an
UnpicklingError exception. This happens with both
pickle and cPickle.
>>> import cPickle as pickle
>>> import pickle as pk
>>> f=open("/dev/null") # Empty file
>>> ff=StringIO("asdfasdfasdfasdfasdfasdf") # Garbage
file
>>> pickle.load(f)
Traceback (most recent call last):
File "<stdin>", line 1, in ?
EOFError
>>> pk.load(f)
Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "/usr/lib/python2.2/pickle.py", line 977, in
load
return Unpickler(file).load()
File "/usr/lib/python2.2/pickle.py", line 592, in
load
dispatch[key](self)
File "/usr/lib/python2.2/pickle.py", line 606, in
load_eof
raise EOFError
EOFError
Problem 2: With cPickle, loading a garbage file
produced and IndexError, not an Unpickling error.
>>> pk.load(ff)
Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "/usr/lib/python2.2/pickle.py", line 977, in
load
return Unpickler(file).load()
File "/usr/lib/python2.2/pickle.py", line 592, in
load
dispatch[key](self)
File "/usr/lib/python2.2/pickle.py", line 746, in
load_dict
k = self.marker()
File "/usr/lib/python2.2/pickle.py", line 600, in
marker
while stack[k] is not mark: k = k-1
IndexError: list index out of range
----------------------------------------------------------------------
You can respond by visiting:
http://sourceforge.net/tracker/?func=detail&atid=105470&aid=504723&group_id=5470