-
-
Notifications
You must be signed in to change notification settings - Fork 5.4k
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
Incorrect @inbounds annotation in Base.last
can result in out-of-bounds memory accesses
#41267
Comments
whoever owns the if someone has a bug in |
It's true that this is against the stated policy of
That stated policy is generally not adhered to. For example, in the docstring of |
Grepping through |
Also with #42573 |
If now "less necessary", sometimes unsafe, and I've seen talk about |
The Lines 554 to 557 in 5f4dec1
|
The
end
keyword in array indexing expressions is lowered tolastindex
. The implementation oflast
in Base callslastindex
inside an@inbounds
expression:julia/base/abstractarray.jl
Lines 452 to 456 in 6dfa690
This use of
@inbounds
goes against the guidance in the@inbounds
documentation to only use it when you can be sure from locally-available information that all array accesses are in bounds. In this case, since the array is only known to be a general subtype ofAbstractVector
and the index value comes from a potentially incorrectly-implemented function, this annotation escalates a buggylastindex
implementation into an out-of-bounds memory access.Here is a simple example using OffsetArrays and a patched
lastindex
method, though the same will work for any array with an incorrect implementation oflastindex
:The text was updated successfully, but these errors were encountered: