Skip to content

BUG: fix swallowed cast error in fancy indexing assignment - #31975

Merged
ngoldbaum merged 1 commit into
numpy:mainfrom
Ijtihed:fix/mapiter-buffered-cast-error-leak
Jul 13, 2026
Merged

BUG: fix swallowed cast error in fancy indexing assignment#31975
ngoldbaum merged 1 commit into
numpy:mainfrom
Ijtihed:fix/mapiter-buffered-cast-error-leak

Conversation

@Ijtihed

@Ijtihed Ijtihed commented Jul 12, 2026

Copy link
Copy Markdown
Contributor

PR summary

Fixes #31974.

arr[idx] = vals can swallow a cast error when the values are buffered and the cast fails while the iterator refills a buffer chunk (array bigger than one 8192-element chunk). the buffered iternext returns 0 on error which looks exactly like a normal end of iteration, so mapiter_set/mapiter_get returned success with the exception still set. depending on what runs next that's either a silent bogus success (the error surfaces at a later unrelated call) or SystemError: ... returned a result with an exception set (e.g. via np.put_along_axis).

this adds a PyErr_Occurred() check after the iteration loops in mapiter_@name@. small arrays already raise cleanly since first-chunk failures are caught at NpyIter_Reset so this just makes big arrays consistent. kept the check unconditional (not needs_api-gated) because non-object casts can fail too, e.g. a string -> int cast hits the same leak

AI Disclosure

Used Claude to double check my work and mae sure I didn't miss anything

Comment thread numpy/_core/src/multiarray/lowlevel_strided_loops.c.src Outdated
Comment thread numpy/_core/src/multiarray/lowlevel_strided_loops.c.src Outdated
@Ijtihed
Ijtihed force-pushed the fix/mapiter-buffered-cast-error-leak branch from ce93ef9 to 59b430d Compare July 13, 2026 09:04
@ngoldbaum ngoldbaum added 00 - Bug 09 - Backport-Candidate PRs tagged should be backported labels Jul 13, 2026
@ngoldbaum

Copy link
Copy Markdown
Member

Thanks @Ijtihed

@ngoldbaum
ngoldbaum merged commit 4e7f3b3 into numpy:main Jul 13, 2026
87 checks passed
@charris charris removed the 09 - Backport-Candidate PRs tagged should be backported label Jul 27, 2026
charris added a commit that referenced this pull request Jul 27, 2026
BUG: fix swallowed cast error in fancy indexing assignment (#31975)
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: cast error during buffered fancy-index assignment is swallowed (SystemError or silently leaked exception)

4 participants