Issue 5794: pickle/cPickle of recursive tuples create pickles that cPickle can't load (original) (raw)

Created on 2009-04-19 19:52 by cwitty, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (5)

msg86177 - (view)

Author: Carl Witty (cwitty)

Date: 2009-04-19 19:52

When I try to pickle a recursive tuple (that recurses through a list), pickle can load the result but cPickle fails with "unpickling stack overflow".

(I just downloaded and built Python 2.6.2 on 64-bit x86 Debian testing to verify this bug; it also fails on Python 2.5.2 on 32-bit x86 Debian testing. I think that probably it doesn't depend on the architecture or operating system at all.)

Here is the test case. At the end, cPickle.loads raises an exception; instead, it should produce an object equivalent to v, like pickle.loads does. (I didn't show it in the test case, but pickles produced by pickle.dumps have the same behavior -- they work with pickle.loads but not cPickle.loads.)

v = ([],) v[0].append(v) import pickle import cPickle v ([([...],)],) vp = cPickle.dumps(v) pickle.loads(vp) ([([...],)],) cPickle.loads(vp) Traceback (most recent call last): File "", line 1, in cPickle.UnpicklingError: unpickling stack underflow

msg86416 - (view)

Author: Collin Winter (collinwinter) * (Python committer)

Date: 2009-04-24 16:51

Interestingly, it only fails with protocol 0:

v = ([],) v[0].append(v) import pickle,cPickle cPickle.loads(pickle.dumps(v, 0)) Traceback (most recent call last): File "", line 1, in cPickle.UnpicklingError: unpickling stack underflow cPickle.loads(pickle.dumps(v, 1)) ([([...],)],) cPickle.loads(pickle.dumps(v, 2)) ([([...],)],)

I'll see if I can come up with a fix.

msg88300 - (view)

Author: Collin Winter (collinwinter) * (Python committer)

Date: 2009-05-25 02:09

Bug-fix patch attached. Alexandre, can you take a look? Feel free to bounce it back if you don't have time.

I'll port to 2.6 and py3k once this is reviewed for trunk.

msg88322 - (view)

Author: Alexandre Vassalotti (alexandre.vassalotti) * (Python committer)

Date: 2009-05-25 19:21

Looks good to me.

msg88376 - (view)

Author: Collin Winter (collinwinter) * (Python committer)

Date: 2009-05-26 16:55

Fixed in r72930 (trunk), r72931 (2.6), r72942 (py3k).

History

Date

User

Action

Args

2022-04-11 14:56:47

admin

set

github: 50044

2009-05-26 16:55:19

collinwinter

set

status: open -> closed
resolution: fixed
messages: +

stage: patch review -> resolved

2009-05-25 19:21:38

alexandre.vassalotti

set

messages: +

2009-05-25 02:09:48

collinwinter

set

files: + rec_tuple.patch

versions: + Python 3.1, Python 2.7, - Python 2.5
keywords: + patch, easy, 26backport
nosy: + alexandre.vassalotti

messages: +
stage: patch review

2009-04-24 16:51:24

collinwinter

set

assignee: collinwinter
messages: +

2009-04-24 16:14:11

collinwinter

set

nosy: + collinwinter

2009-04-19 19:52:59

cwitty

create