python / python/cpython

Crash in `create_elementiter` when OOM

Open
#148,731 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

extension-modules topic-XML type-crash
Dominant language
Python
Stars
77.2k
Forks
35.9k
PR merge metrics
PR metrics pending

Description

Crash report

What happened?
import _testcapi
from xml.etree.ElementTree import Element

e = Element('root')

_testcapi.set_nomemory(1, 2)
try:
    e.iter()
except MemoryError:
    pass
finally:
    _testcapi.remove_mem_hooks()

With UBSan enabled, I get:

Modules/_elementtree.c:2176:9: runtime error: applying non-zero offset 15914838024376868032 to null pointer
Segmentation fault         (core dumped)
CPython versions tested on:

CPython main branch

Operating systems tested on:

No response

Output from running 'python -VV' on the command line:

No response

Linked PRs
  • gh-148838
  • gh-152120

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in Modules/_elementtree.c around create_elementiter and reproduce the reported e.iter() case with _testcapi.set_nomemory under UBSan. Review linked PRs gh-148838 and gh-152120; done means the out-of-memory path no longer triggers the null-pointer offset diagnostic or segmentation fault.

Written by the indexing model from the issue text.

Assessment

Tech stack
c, python
Domain
backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.