Author Oren Milman
Recipients Oren Milman
Date 2017-09-27.10:43:58
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1506509038.4.0.154975027568.issue31608@psf.upfronthosting.co.za>
In-reply-to
Content
The following code causes the interpreter to crash:

import _collections
class BadDeque(_collections.deque):
    def __new__(cls, *args):
        if len(args):
            return 42
        return _collections.deque.__new__(cls)

BadDeque() * 42

(The interpreter would crash also if we replaced 'BadDeque() * 42' with
'BadDeque() + _collections.deque([42])'.)

This is because deque_copy() (in Modules/_collectionsmodule.c) returns whatever
BadDeque() returned, without verifying it is a deque.
deque_repeat() assumes that deque_copy() returned a deque, and passes it to
deque_inplace_repeat(), which assumes it is a deque, and crashes.

(Similarly, deque_concat() assumes that deque_copy() returned a deque, which
is the reason for the other crash.)


ISTM it is a very unlikely corner case, so that adding a test (as well as
a NEWS.d item) for it is unnecessary.
What do you think?
History
Date User Action Args
2017-09-27 10:43:58Oren Milmansetrecipients: + Oren Milman
2017-09-27 10:43:58Oren Milmansetmessageid: <1506509038.4.0.154975027568.issue31608@psf.upfronthosting.co.za>
2017-09-27 10:43:58Oren Milmanlinkissue31608 messages
2017-09-27 10:43:58Oren Milmancreate