FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

BUG: core: result_type(0, np.timedelta64(4)) would seg. fault. by WarrenWeckesser · Pull Request #20088 · numpy/numpy · GitHub

/ numpy Public

BUG: core: result_type(0, np.timedelta64(4)) would seg. fault. - #20088

Merged
charris merged 3 commits into
numpy:mainfrom
WarrenWeckesser:fix-gh-200077
Oct 11, 2021
Merged

charris merged 3 commits into
numpy:mainfrom
WarrenWeckesser:fix-gh-200077

Conversation

WarrenWeckesser commented Oct 10, 2021
edited
Loading

Copy link
Copy Markdown
Member

Before this change, the line in convert_datatype.c

result = PyArray_CastDescrToDType(all_descriptors[0], common_dtype);

would trigger a seg. fault with a call such as

np.result_type(0, np.timedelta64(4))

The problem was that all_descriptors[0] was NULL, and it was
dereferenced in PyArray_CastDescrToDType.

The code in the loop that followed the above line avoided passing
NULL values in all_descriptors[i] to PyArray_CastDescrToDType by
checking that the corresponding input argument to result_type
was not a Python scalar. A different code path was taken in that
case. The seg. fault is fixed by applying that same check to the
first argument.

Closes gh-20077.

Copy link
Copy Markdown
Member Author

I don't know what went wrong with the Travis CI Python 3.10-dev job, but I suspect it is not related to this PR. The log has just one line:

An error occurred while generating the build script.

Before this change, the line in convert_datatype.c

    result = PyArray_CastDescrToDType(all_descriptors[0], common_dtype);

would trigger a seg. fault with a call such as

    np.result_type(0, np.timedelta64(4))

The problem was that `all_descriptors[0]` was NULL, and it was
dereferenced in PyArray_CastDescrToDType.

The code in the loop that followed the above line avoided passing
NULL values in all_descriptors[i] to PyArray_CastDescrToDType by
checking that the corresponding input argument to `result_type`
was not a Python scalar.  A different code path was taken in that
case.  The seg. fault is fixed by applying that same check to the
first argument.

Closes numpygh-20077.

Copy link
Copy Markdown
Member Author

Force-pushed a trivial change. All the tests pass--I guess the Travis CI issue was a transient one.

seberg added the 09 - Backport-Candidate PRs tagged should be backported label Oct 11, 2021
seberg added this to the 1.21.3 release milestone Oct 11, 2021

seberg left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Thanks, annoying complexity here with that value-based promotion/casting :(. An obvious fix though, since it just extends the ugly logic from above.

My only comment is to try to be a bit more clear that this helper only makes sense in the context of np.result_type

* See that function for the meaning and contents of the parameters.
*/
static PyArray_Descr *
get_dtype_from_descr_and_common(

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Maybe rename to get_descr_from_cast_or_value? But not sure.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

(I am tempted to overindent the arguments, but it is probably just me who does that...)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Done.

charris merged commit 8c9cf79 into numpy:main Oct 11, 2021

charris commented Oct 11, 2021

Copy link
Copy Markdown
Member

Thanks Warren.

WarrenWeckesser deleted the fix-gh-200077 branch October 11, 2021 19:46
charris added a commit to charris/numpy that referenced this pull request Oct 12, 2021
charris removed the 09 - Backport-Candidate PRs tagged should be backported label Oct 12, 2021
charris removed this from the 1.21.3 release milestone Oct 12, 2021
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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

BUG: np.result_type segfault on timedelta64 and int

3 participants


Back | FazBrowse Home | New Git URL