GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||||||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||||||||||||||||||||||||||||||||||
GeezerVison is showing github.com — BUG: Refactor error handling in array_setstate to prevent typecode leak by whyvineet · Pull Request #31701 · numpy/numpy Conversation
Contributor
PR summaryThis fixes the reference-count imbalance reported in #31678 AI DisclosureNo AI tools used
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions
da-woods
reviewed
|
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
This seems like it might still be leaking typecode
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
and here?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
and here?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
I agree @da-woods; the current From what I understand, the goal is to keep local references consistent, either owned or I'll take a look at restructuring the ownership and cleanup logic along those lines. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
A few small comments (only one of which is a real error I think) but to me that looks much more likely to work right.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| * Direct pointer path: PyArray_SetBaseObject steals the rawdata | ||
| * reference. NULL rawdata afterward so Py_XDECREF at the end | ||
| * label does not double-decref a stolen ref. | ||
| */ | ||
| fa->mem_handler = NULL; | ||
| fa->data = datastr; | ||
| if (PyArray_SetBaseObject(self, rawdata) < 0) { |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Most reference steeling functions (including PyArray_SetBaseObject it looks like) steal a reference on both success and failure to be consistent
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
I’ll recheck the ownership contract here... and adjust the cleanup accordingly
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| Py_DECREF(fa->descr); | ||
| fa->descr = swapped; |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
You might be better doing Py_SETREF(fa->descr, swapped) (because can in principle cause arbitrary code to execute so you're leaving it in an potentially invalid state while that happens).
I don't think it can actually happen here, but I think it's a good idea anyway
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Okay... I’ll switch this assignment.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| Py_DECREF(fa->descr); | ||
| fa->descr = swapped; |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
And here with Py_SETREF
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Here as well...
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
I looked at how I changed the code to transfer ownership before calling Could you take another look, @da-woods? Does this match what you had in mind? |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
Yes that looks right to me. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Thanks @whyvineet and especially also @da-woods for reviewing. This is a bit of a dark corner, the fix is I think in a sense meaningless (you would need a bad pickle to hit it and at that point anything is possible).
(We use finish: more often than end: but I don't feel like style nitpicking, let's get it in.)
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
FIX: Refactor error handling in array_setstate to prevent typecode leak (#31701)
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.