Skip to content

BUG: fix crash in ufunc.resolve_dtypes with a Python scalar type - #32496

Merged
ngoldbaum merged 1 commit into
numpy:mainfrom
ngoldbaum:fix-resolve-dtypes-crash
Sep 4, 2026
Merged

ngoldbaum merged 1 commit into
numpy:mainfrom
ngoldbaum:fix-resolve-dtypes-crash

Conversation

@ngoldbaum

Copy link
Copy Markdown
Member

PR summary

The Python ufunc.resolve_dtypes helper calls into this function without passing an explicit scalar object. This leads to a null-pointer dereference crash generating the error message for any of the cases in the test I added.

The fix is to check the operand flags if the scalar is NULL.

AI Disclosure

An AI model found the bug. I wrote the fix and had the model review it.

@ngoldbaum ngoldbaum added 00 - Bug 09 - Backport-Candidate PRs tagged should be backported labels Sep 3, 2026
@jorenham

jorenham commented Sep 3, 2026

Copy link
Copy Markdown
Member

related to #31734 ?

@ngoldbaum
ngoldbaum force-pushed the fix-resolve-dtypes-crash branch from 8007907 to 2fc4217 Compare September 3, 2026 21:30
@ngoldbaum

Copy link
Copy Markdown
Member Author

Nah, this is a different error path that is way less likely to be hit in real life. I hit this working on a fix for #32491.

@mhvk mhvk left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. It seems slightly odd that scaler can be NULL, but maybe that's the price to pay for cross-using code. In any case, this doesn't hurt anything.

@ngoldbaum
ngoldbaum force-pushed the fix-resolve-dtypes-crash branch from 2fc4217 to ac93346 Compare September 4, 2026 17:06
@ngoldbaum
ngoldbaum merged commit 5986d34 into numpy:main Sep 4, 2026
91 checks passed
@ngoldbaum

Copy link
Copy Markdown
Member Author

Thanks for the review!

@charris charris removed the 09 - Backport-Candidate PRs tagged should be backported label Sep 5, 2026
charris added a commit that referenced this pull request Sep 5, 2026
BUG: fix crash in ufunc.resolve_dtypes with a Python scalar type (#32496)
ngoldbaum added a commit to ngoldbaum/numpy that referenced this pull request Sep 8, 2026
ngoldbaum added a commit to ngoldbaum/numpy that referenced this pull request Sep 8, 2026
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.

4 participants