Skip to content

BUG: fix segfault on deeply nested structured dtype (gh-32488) - #32622

Open
BHUVANSH855 wants to merge 3 commits into
numpy:mainfrom
BHUVANSH855:fix-nested-dtype-zerofill-segfault
Open

BHUVANSH855 wants to merge 3 commits into
numpy:mainfrom
BHUVANSH855:fix-nested-dtype-zerofill-segfault

Conversation

@BHUVANSH855

Copy link
Copy Markdown
Contributor

PR summary

Fixes #32488.

Creating an array from a sufficiently deeply nested structured dtype segfaults instead of raising a catchable exception. Resolving the zerofill traverse function for such a dtype recurses once per nesting level in npy_get_zerofill_void_and_legacy_user_dtype_loop, with no termination check, so a deep enough dtype exhausts the C stack.

The fix adds a Py_EnterRecursiveCall guard via a thin wrapper around the existing function, following the same pattern used for self-containing arrays (gh-8306, gh-9077).

This fixes the crash as reported in the issue (verified against the reporter's own repro, which now raises RecursionError instead of segfaulting). It does not fully cover the artificially small (1 MiB) thread-stack reproducer also posted in the issue, that's a general limitation of counter-based recursion guards rather than something specific to this fix, same caveat noted in gh-32620.

Added a regression test in TestMonsterType following the existing test_dict_recursion/test_list_recursion style. Ran the full test_dtype.py suite (1181 passed) and the zerofill/structured/dtype subset of test_multiarray.py (195 passed) with no regressions.

First time contributor introduction

Still new to numpy, background in CPython tooling. Found this one from the "Looking for Contributor" board after that PR.

AI Disclosure

No AI tools used.

@ngoldbaum

Copy link
Copy Markdown
Member

max test failures are real

@InessaPawson

Copy link
Copy Markdown
Member

Hi, @BHUVANSH855 ! Thank you for your interest in contributing to NumPy. As the label indicates, #32488 is reserved for participants in the NumFOCUS Sustaining Open Source Series. As well as #32609. Could you let us know which organization you’re part of?

@BHUVANSH855

BHUVANSH855 commented Sep 15, 2026

Copy link
Copy Markdown
Contributor Author

@ngoldbaum
all checks pass now.

@InessaPawson
i seen the issue was added to project where the issue status was looking for contributors. So, I grabbed it. If there's a criteria I will take care from next time. I am not the part of any of organization.

@InessaPawson

Copy link
Copy Markdown
Member

@InessaPawson i seen the issue was added to project where the issue status was looking for contributors. So, I grabbed it. If there's a criteria I will take care from next time. I am not the part of any of organization.

Hmmm... Isn't the board titled NumFOCUS Sustaining Open Source Series 2026?...

NF-ghboard

@BHUVANSH855 Please do not take any additional issues from this board, as these issues are reserved for participants in the program.
You are, of course, welcome to contribute to NumPy by picking up any other issues from the main issue tracker that are not labeled sprint-2026. Thank you for respecting other people's time and effort.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

BUG: SIGSEGV when creating an array from a deeply nested structured dtype

3 participants