Skip to content
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

BitArray "constructor" incorrectly assumes 1-based indexing, leading to nondeterministic incorrect results due to out-of-bounds memory access #45825

Closed
yurivish opened this issue Jun 26, 2022 · 0 comments · Fixed by #45835
Assignees
Labels
arrays [a, r, r, a, y, s] bug Indicates an unexpected problem or unintended behavior

Comments

@yurivish
Copy link
Contributor

For example, in the following code, a BitArray that is constructed from an input array of values that are all false is found to contain some values that are true:

julia> using OffsetArrays

julia> all_false = falses(-1000:1000);

julia> any(==(true), all_false)
false

julia> all_false_bitarray = BitArray(all_false);

julia> any(==(true), all_false_bitarray)
true

This is due to the code here, which applies @inbounds to a loop before proceeding to index the user-provided array with indices that start from one.

julia/base/bitarray.jl

Lines 510 to 514 in 2168230

@inbounds begin
for i = 1:length(Bc)-1
c = UInt64(0)
for j = 0:63
c |= (UInt64(convert(Bool, A[ind])::Bool) << j)

@KristofferC KristofferC added the bug Indicates an unexpected problem or unintended behavior label Jun 26, 2022
@JeffBezanson JeffBezanson self-assigned this Jun 27, 2022
@JeffBezanson JeffBezanson added the arrays [a, r, r, a, y, s] label Jun 27, 2022
KristofferC pushed a commit that referenced this issue Jul 20, 2022
ffucci pushed a commit to ffucci/julia that referenced this issue Aug 11, 2022
pcjentsch pushed a commit to pcjentsch/julia that referenced this issue Aug 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
arrays [a, r, r, a, y, s] bug Indicates an unexpected problem or unintended behavior
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants