Skip to content

gh-148731: Fix Element.iter() crash on OOM#148838

Open
gz83 wants to merge 1 commit intopython:mainfrom
gz83:gh-148731
Open

gh-148731: Fix Element.iter() crash on OOM#148838
gz83 wants to merge 1 commit intopython:mainfrom
gz83:gh-148731

Conversation

@gz83
Copy link
Copy Markdown

@gz83 gz83 commented Apr 21, 2026

Initialize the Element iterator state needed for OOM handling before allocating parent_stack, and keep the OOM regression test scoped to the test that uses _testcapi.

Add a regression test for the MemoryError path in Element.iter().

Tests run:

  • ./python -m test test_xml_etree_c
  • Reproduced the issue with the UBSan build before the fix
  • Verified that the UBSan reproducer no longer crashes after the fix

@python-cla-bot
Copy link
Copy Markdown

python-cla-bot Bot commented Apr 21, 2026

All commit authors signed the Contributor License Agreement.

CLA signed

@gz83
Copy link
Copy Markdown
Author

gz83 commented Apr 21, 2026

@StanFromIreland

Hello, please take a look at this patch. Also, this is my first time contributing a patch to cpython, so please point out any shortcomings. Thank you!

Comment thread Lib/test/test_xml_etree_c.py Outdated
Comment thread Lib/test/test_xml_etree_c.py
Comment thread Modules/_elementtree.c Outdated
Comment thread Modules/_elementtree.c Outdated
Initialize the Element iterator state needed for OOM handling before
allocating parent_stack, and keep the OOM regression test scoped to
the test that uses _testcapi.

Add a regression test for the MemoryError path in Element.iter().
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants