Conversation
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.
Description
array::check_dimensions_impl(reached throughbyte_offset,offset_at,index_at,data,mutable_data, andarray_t::at/mutable_at) only testedi >= *shape, andarray::shape(dim)/array::strides(dim)only testeddim >= ndim(). A negative index or axis forwarded from Python passed the out-of-bounds guard and yielded a negative byte offset, i.e. an access before the start of the buffer. Forat/datathat is an out-of-bounds read; formutable_at/mutable_datait is an out-of-bounds write at a caller-chosen negative offset.Built against
py::array_t<uint16_t>,a.at(-1)reads two bytes before the allocation (ASan reports heap-buffer-overflow) anda.mutable_at(-4096) = vwrites far below it. These accessors already document that they throw when an index is out of bounds; a negative value is out of bounds, so the lower-bound check belongs in the accessor rather than at every binding call site. With the fix all three raiseindex_errorthe same way an over-large index does.Added negative-index and negative-axis cases to the existing
test_bounds_checkandtest_array_attributes; they fail on the current code and pass with the fix.Suggested changelog entry:
array/array_telement and shape/stride accessors now raiseIndexErrorinstead of addressing memory before the start of the buffer.