Skip to content

BUG: check return value from PyArray_PromoteTypes #12032

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 27, 2018

Conversation

mattip
Copy link
Member

@mattip mattip commented Sep 25, 2018

Fixes #12031. by checking the return value from PyArray_PromoteTypes. Also make sure to decref otmp on error.

@charris
Copy link
Member

charris commented Sep 25, 2018

I have no idea why the debug build is segfaulting.

Copy link
Member

@eric-wieser eric-wieser left a comment

Choose a reason for hiding this comment

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

This isn't safe. There are two loops here - one of the decrefs no matter how it exits, and the other doesn't. I think the thing to do here is push otmp into the local scope of each loop.

@mattip
Copy link
Member Author

mattip commented Sep 25, 2018

Fixing otmp, the decref caused the segfault.

PyObject *otmp = PySequence_GetItem(op, i);
if (otmp == NULL) {
goto fail;
}
if (!PyArray_CheckAnyScalar(otmp)) {
newtype = PyArray_DescrFromObject(otmp, intype);
Py_XDECREF(intype);
Copy link
Member

Choose a reason for hiding this comment

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

Put the decref on this line, and then you can omit it below.

Copy link
Member Author

Choose a reason for hiding this comment

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

done

@@ -2081,14 +2084,15 @@ PyArray_ConvertToCommonType(PyObject *op, int *retn)
newtype = PyArray_DescrFromObject(otmp, stype);
Py_XDECREF(stype);
Copy link
Member

Choose a reason for hiding this comment

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

Same again - you're done with the object already by this line, so can decref it immediately

Copy link
Member Author

Choose a reason for hiding this comment

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

done

@eric-wieser eric-wieser merged commit d382a54 into numpy:master Sep 27, 2018
@eric-wieser
Copy link
Member

Thanks @mattip!

@mattip mattip deleted the choose-crash branch March 4, 2019 13:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants