[ python-Bugs-952807 ] segfault in subclassing datetime.date & pickling

SourceForge.net noreply at sourceforge.net
Wed May 12 15:30:11 EDT 2004


Bugs item #952807, was opened at 2004-05-12 21:30
Message generated for change (Tracker Item Submitted) made by Item Submitter
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=952807&group_id=5470

Category: Extension Modules
Group: None
Status: Open
Resolution: None
Priority: 5
Submitted By: Thomas Wouters (twouters)
Assigned to: Nobody/Anonymous (nobody)
Summary: segfault in subclassing datetime.date & pickling

Initial Comment:
datetime.date does not take subclassing into account
properly. datetime.date's tp_new has special code for
unpickling (the single-string argument) which calls
PyObject_New() directly, which doesn't account for the
fact that subclasses may participate in cycle-gc (even
if datetime.date objects do not.)

The result is a segfault in code that unpickles
instances of subclasses of datetime.date:

import pickle, datetime
class mydate(datetime.date): pass
s = pickle.dumps(mydate.today())
broken = pickle.loads(s)
del broken

The 'del broken' is what causes the segfault: the
'mydate' class/type is supposed to participate in GC,
but because of datetime.date's shortcut, that part of
the object is never initialized (nor allocated, I
presume.) The 'broken' instance reaches 0 refcounts,
the GC gets triggered and it reads garbage memory. To
'prove' that the problem isn't caused by pickle itself:

class mydate(datetime.date): pass
broken = mydate('\x07\xd4\x05\x0c')
del broken

causes the same crash, in the GC code.


----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=952807&group_id=5470



More information about the Python-bugs-list mailing list