[New-bugs-announce] [issue1517] lookdict should INCREF/DECREF startkey around PyObject_RichCompareBool

Adam Olsen report at bugs.python.org
Thu Nov 29 02:41:10 CET 2007

New submission from Adam Olsen:

(thanks go to my partner in crime, jorendorff, for helping flesh this out.)

lookdict calls PyObject_RichCompareBool without using INCREF/DECREF on
the key passed.  It's possible for the comparison to delete the key from
the dict, causing its own argument to be deallocated.  This can lead to
bogus results or a crash.

A custom type with its own __eq__ method will implicitly INCREF the key
when passing it as an argument, which prevents incorrect behaviour from
manifesting.  There are a couple ways around this though, as shown in my

components: Interpreter Core
files: dictbug.py
messages: 57925
nosy: rhamphoryncus
severity: normal
status: open
title: lookdict should INCREF/DECREF startkey around PyObject_RichCompareBool
Added file: http://bugs.python.org/file8820/dictbug.py

Tracker <report at bugs.python.org>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: dictbug.py
Type: text/x-python
Size: 2071 bytes
Desc: not available
Url : http://mail.python.org/pipermail/new-bugs-announce/attachments/20071129/68ebbf6f/attachment-0001.py 

More information about the New-bugs-announce mailing list