Repository navigation
Conversation
| Py_XDECREF(src_ref); | ||
| memset(src, 0, sizeof(PyObject *)); | ||
| Py_XDECREF(src_ref); | ||
| NPY_DT_DBG_REFTRACE("dec src ref (cast object -> not object)", src_ref); |
There was a problem hiding this comment.
Since we decref src_ref on line 692, should we move the debug log on line 693 up? It can read a freed object.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PR summary
Fixes #33594 (and a lot more!). @nevercodecorrect I'd appreciate your opinion on this. Also ping @vstinner in case this piques your interest.
This fixes systemic lifetime issues in object operations. See #33594 for details, but in short see the docs for
Py_SETREFwhich describe the problem. Decrefing can execute Python code, and if that code reads or assigns to the array element while it still points at the object being destroyed, we get UB. So we need to store the new value in the slot before releasing the old one.I can't use
Py_SETREFeverywhere because we support unaligned object fields in structured dtypes andSETREFneeds aligned pointers.AI Disclosure
I worked on this with an AI model.