This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Infinite recursion in Pickle
Type: Stage:
Components: Library (Lib) Versions: Python 2.2
process
Status: closed Resolution: duplicate
Dependencies: Superseder:
Assigned To: gvanrossum Nosy List: gvanrossum, phd
Priority: low Keywords:

Created on 2002-07-02 15:02 by phd, last changed 2022-04-10 16:05 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
test-pickle.tgz phd, 2002-07-02 15:02 The archive with the initial pickle, the module with classess, and test program.
Messages (5)
msg11432 - (view) Author: Oleg Broytman (phd) * Date: 2002-07-02 15:02
Pickle falls into infininite recursion, cPickle crashed
(segfault on Linux, bus error on FreeBSD). See the
attached file. There is initial pickle (just a very
simple though somewhat large tree of bookmarks;
unfortunately lesser tree does not trigger the bug);
bkmk_objects.py module that includes class definitions
for the pickled object, and simple test program that
demonstrates the bug.

The program loads initial pickle, runs a function upon
it and saves the pickle back. The function runs through
the entire tree and creates backlinks - every object
got a link to its parent folder.

So it seems the bug is related to pickling objects with
loops.

When I changed builtin list as a parent class of Folder
to UserList (and recreated initial pickle) the bug
disappeared, so I think the bug is related to pickling
new classes.
msg11433 - (view) Author: Guido van Rossum (gvanrossum) * (Python committer) Date: 2002-08-02 20:26
Logged In: YES 
user_id=6380

Mmm, interesting.
msg11434 - (view) Author: Guido van Rossum (gvanrossum) * (Python committer) Date: 2002-08-02 20:42
Logged In: YES 
user_id=6380

Oleg, could it be that your data structure is just very
deeply nested? On my machine (RedHat Linux 7.2), your test
program completes without problem, so there doesn't seem to
be something in the data that inherently triggers a bug.
However, when I apply Martin von Loewis's patch from SF bug
576084, cPickle raises RuntimeError: maximum recursion depth
exceeded. I'm guessing that you are building what is in
essence a very long doubly-linked list; the pickle algorithm
necessarily has to enter a recursion level for each list
node in this case.

Switching to UserList probably reduces the number of stack
frames per recursion level and that would explain that it
doesn't fail.
msg11435 - (view) Author: Oleg Broytman (phd) * Date: 2002-08-03 04:34
Logged In: YES 
user_id=4799

> could it be that your data structure is just very deeply nested?
[skip]
> I'm guessing that you are building what is in essence a very long doubly-linked list

I thought about it. It is not vrey deeply nested, just very long. So what should I do? Devise a formula that calculates recusion limit depending on the number of objects and call sys.setrecursionlimit()? Or just call sys.setrecursionlimit() in a loop, catching RuntimeError and increasing recusrion limit?

In any case I hope to see cPickle patched so it will not crash with a reasonable recursion limit.
msg11436 - (view) Author: Guido van Rossum (gvanrossum) * (Python committer) Date: 2002-08-03 14:38
Logged In: YES 
user_id=6380

Well, from the POV of pickle, a long chain is
indistinguishable from a deeply nested structure. cPickle
*will* be fixed (by the patch of bug 576084). So I'm going
to close this as a duplicate.
History
Date User Action Args
2022-04-10 16:05:28adminsetgithub: 36838
2002-07-02 15:02:46phdcreate