Skip to content

BUG: avoid possible stack overflow in arraydescr_dealloc (#32133) - #32158

Merged
charris merged 1 commit into
numpy:maintenance/2.5.xfrom
charris:backport-32133
Jul 31, 2026
Merged

BUG: avoid possible stack overflow in arraydescr_dealloc (#32133)#32158
charris merged 1 commit into
numpy:maintenance/2.5.xfrom
charris:backport-32133

Conversation

@charris

@charris charris commented Jul 31, 2026

Copy link
Copy Markdown
Member

Backport of #32133.

PR summary

The Py_DECREF(lself->subarray->base) we currently have can lead to situations where the DECREF causes a deallocation, which then recursively calls into arraydescr_dealloc. With a properly setup dtype, this can lead to a stack overflow on newer Python versions. See python/cpython#142253 for the upstream issue that was opened about that and #30370 on the NumPy side.

My fix is to check for cases when decrefing will deallocate and in those cases explicitly detach the base before decrefing, avoiding the recursive call.

AI Disclosure

I used an AI model to understand the problem and debug the fix and new test.

@charris charris added this to the 2.5.2 release milestone Jul 31, 2026
@charris charris added 00 - Bug 08 - Backport Used to tag backport PRs labels Jul 31, 2026
@charris
charris merged commit 988d94d into numpy:maintenance/2.5.x Jul 31, 2026
99 of 101 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

00 - Bug 08 - Backport Used to tag backport PRs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants