[New-bugs-announce] [issue36956] Calling "functions" used to implement generators/comps easily cause crash

Dan Snider report at bugs.python.org
Sat May 18 09:53:21 EDT 2019


New submission from Dan Snider <mr.assume.away at gmail.com>:

As far as I know, generators, set comprehensions, list comprehensions, and dict comprehensions, (along with their asynchronous variants) are implemented by first calling the GET_(A)ITER opcode and then building and calling a function that acepts the resulting iterator as its sole argument.

Assigning the code object used to make that function (or using it in the types.FunctionType constructor) and then calling it with a non-iterator argument will obviously cause a crash since the FOR_ITER opcode rightly expects that it will never have to deal with non-iterators and calls tp_iternext without checking if it exists.

The 4-liner demonstrates the crash:

if 1:
  fn = lambda: None
  gi = (i for i in ())
  fn.__code__ = gi.gi_code
  [*fn("abc")]

----------
messages: 342797
nosy: bup
priority: normal
severity: normal
status: open
title: Calling "functions" used to implement generators/comps easily cause crash
type: crash
versions: Python 3.6, Python 3.7, Python 3.8

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue36956>
_______________________________________


More information about the New-bugs-announce mailing list