8000 BUG: non-integers can end up in dtype offsets by ahaldane · Pull Request #8080 · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to content

BUG: non-integers can end up in dtype offsets #8080

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 1 commit into from
Sep 23, 2016

Conversation

ahaldane
Copy link
Member

Fix is to convert offsets to python ints at dtype creation.
Fixes #8059

@@ -1072,7 +1072,13 @@ _convert_from_dict(PyObject *obj, int align)
goto fail;
}
offset = PyInt_AsLong(off);
PyTuple_SET_ITEM(tup, 1, off);
if (PyErr_Occurred()) {
Copy link
Member

Choose a reason for hiding this comment

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

if ((offset == -1) && PyErr_Occured()) { avoids the check most of the time I think.

Copy link
Member

Choose a reason for hiding this comment

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

Two rather unrelated side points I am not sure about:

  1. What about floats, etc.? Maybe it would make sense to use the Index conversion stuff?
  2. Where do we check int size? We only support integer sized offsets (since dtype is limited to int).

Copy link
Member Author

Choose a reason for hiding this comment

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

what is the index conversion stuff? I don't think I'm familiar and searching didn't help.

Copy link
Member Author

Choose a reason for hiding this comment

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

also PyInt_AsLong takes care of floats etc

Copy link
Member

Choose a reason for hiding this comment

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

I mean our own (or the python version we mostly call there) NpyPyIntAsIntp (or whate it was), which specificially does not allow floats.

@ahaldane
Copy link
Member Author

Got it, and updated.

I also added a check that offset is positive - previously negative was allowed and I could read far back in memory! Also I made the conversion of itemsize safer.

Fix is to convert offsets to python ints at dtype creation.
Fixes numpy#8059
@seberg
Copy link
Member
seberg commented Sep 22, 2016

Nice. Hmmmpff, I may have thought too little about my comments, though. At least if we want to backport this, the more strict integer conversion could be a regression (though maybe it cannot be, because this is almost always only called indirectly).

@ahaldane
Copy link
Member Author

Anyone trying to use weird non-integer offsets would probably cause numpy to blow up in other ways ...probably.

Also, I checked and #8059 is not a new bug I introduced, it is old. I checked in 1.8.0 and 1.10.0 and the examples raise exceptions back then too.

Personally I would not worry about a backport, I think, since this is such an old and obscure oversight.

@seberg
Copy link
Member
seberg commented Sep 23, 2016

OK, then I think I am happy. Thanks.

@seberg seberg merged commit 6463a76 into numpy:master Sep 23, 2016
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
0