ArrayFire.jl icon indicating copy to clipboard operation
ArrayFire.jl copied to clipboard

Accessing array elements out of range in a view is accepted in Julia

Open daniloefl opened this issue 5 years ago • 0 comments

Dear developers,

as mentioned in https://github.com/SciML/DiffEqFlux.jl/issues/436 ArrayFire crashes due to an access to a[(length(a)+1):end]. However, this is an allowed syntax in Julia and it is expected to return an empty array. See [1] below.

A fix would be to check the indices before doing ccall in indexing.jl.

Best regards, Danilo

[1]

Example:

julia> a = [1 2 3]
1×3 Array{Int64,2}:
 1  2  3

julia> a[4:end]
Int64[]

julia> a[5:end]
Int64[]

julia> using ArrayFire
ArrayFire v3.7.2 (OpenCL, 64-bit Linux, build 218dd2c9)
[0] Clover: AMD TURKS (DRM 2.50.0 / 5.4.0-40-generic, LLVM 10.0.0), 1024 MB

julia> a2 = AFArray(a)
AFArray: 1×3 Array{Int64,2}:
 1  2  3

julia> a2[4:end]
ERROR: ArrayFire Error (202) : Invalid input argument
In function af_err af_index_gen(void**, af_array, dim_t, const af_index_t*)
In file src/api/c/index.cpp:220


 0# 0x00007F2CBE931DF2 in /home/daniloefl/arrayfire/lib/libafopencl.so.3
 1# af_index_gen in /home/daniloefl/arrayfire/lib/libaf.so.3
 2# 0x00007F2CD0843223
 3# 0x00007F2CD0843346
 4# 0x00007F2CF104D25C in /home/daniloefl/Computer/julia/usr/bin/../lib/libjulia.so.1
 5# 0x00007F2CF104CE7A in /home/daniloefl/Computer/julia/usr/bin/../lib/libjulia.so.1
 6# 0x00007F2CF104DB50 in /home/daniloefl/Computer/julia/usr/bin/../lib/libjulia.so.1
 7# 0x00007F2CF104E687 in /home/daniloefl/Computer/julia/usr/bin/../lib/libjulia.so.1
 8# 0x00007F2CF106C0C1 in /home/daniloefl/Computer/julia/usr/bin/../lib/libjulia.so.1
 9# 0x00007F2CF106C759 in /home/daniloefl/Computer/julia/usr/bin/../lib/libjulia.so.1
10# 0x00007F2CF106C759 in /home/daniloefl/Computer/julia/usr/bin/../lib/libjulia.so.1
11# jl_toplevel_eval_in in /home/daniloefl/Computer/julia/usr/bin/../lib/libjulia.so.1
12# 0x00007F2CE2BF1092 in /home/daniloefl/Com
Stacktrace:
 [1] error(::String) at ./error.jl:33
 [2] _error(::UInt32, ::Bool) at /home/daniloefl/.julia/packages/ArrayFire/U0hth/src/util.jl:96
 [3] index_gen_1 at /home/daniloefl/.julia/packages/ArrayFire/U0hth/src/indexing.jl:91 [inlined]
 [4] getindex(::AFArray{Int64,2}, ::UnitRange{Int64}) at /home/daniloefl/.julia/packages/ArrayFire/U0hth/src/indexing.jl:66
 [5] top-level scope at REPL[6]:1

daniloefl avatar Oct 17 '20 17:10 daniloefl