Skip to content

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

Closed
@yurivish

Description

@yurivish

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)

Metadata

Metadata

Assignees

Labels

arrays[a, r, r, a, y, s]bugIndicates an unexpected problem or unintended behavior

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions