JuliaGraphs / StaticGraphs.jl

Memory-efficient immutable LightGraphs.
Other
33 stars 8 forks source link

`neighbors` segfaults on large out of bounds indices #33

Open AayushSabharwal opened 2 years ago

AayushSabharwal commented 2 years ago

Trying to run neighbors on a StaticDiGraph using a sufficiently large out-of-bounds index results in a segfault.

Reproducible Example:

using Graphs
using StaticGraphs
g = SimpleDiGraph([0 1 1; 0 0 1; 0 0 0])
gg = StaticDiGraph(g)
neighbors(gg, 256222222)

Results in:

signal (11): Segmentation fault
in expression starting at REPL[14]:1
unitrange_last at ./range.jl:359 [inlined]
UnitRange at ./range.jl:354 [inlined]
Colon at ./range.jl:5 [inlined]
Colon at ./range.jl:3 [inlined]
_fvrange at /home/aayush/.julia/packages/StaticGraphs/l0WpK/src/StaticGraphs.jl:67 [inlined]
fadj at /home/aayush/.julia/packages/StaticGraphs/l0WpK/src/StaticGraphs.jl:71 [inlined]
outneighbors at /home/aayush/.julia/packages/StaticGraphs/l0WpK/src/StaticGraphs.jl:89 [inlined]
neighbors at /home/aayush/.julia/packages/Graphs/Mih78/src/core.jl:242
unknown function (ip: 0x7f63f36ba343)
_jl_invoke at /buildworker/worker/package_linux64/build/src/gf.c:2247 [inlined]
jl_apply_generic at /buildworker/worker/package_linux64/build/src/gf.c:2429
jl_apply at /buildworker/worker/package_linux64/build/src/julia.h:1788 [inlined]
do_call at /buildworker/worker/package_linux64/build/src/interpreter.c:126
eval_value at /buildworker/worker/package_linux64/build/src/interpreter.c:215
eval_stmt_value at /buildworker/worker/package_linux64/build/src/interpreter.c:166 [inlined]
eval_body at /buildworker/worker/package_linux64/build/src/interpreter.c:587
jl_interpret_toplevel_thunk at /buildworker/worker/package_linux64/build/src/interpreter.c:731
jl_toplevel_eval_flex at /buildworker/worker/package_linux64/build/src/toplevel.c:885
jl_toplevel_eval_flex at /buildworker/worker/package_linux64/build/src/toplevel.c:830
jl_toplevel_eval_flex at /buildworker/worker/package_linux64/build/src/toplevel.c:830
jl_toplevel_eval_in at /buildworker/worker/package_linux64/build/src/toplevel.c:944
eval at ./boot.jl:373 [inlined]
eval_user_input at /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.7/REPL/src/REPL.jl:150
repl_backend_loop at /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.7/REPL/src/REPL.jl:244
start_repl_backend at /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.7/REPL/src/REPL.jl:229
#run_repl#47 at /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.7/REPL/src/REPL.jl:362
run_repl at /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.7/REPL/src/REPL.jl:349
_jl_invoke at /buildworker/worker/package_linux64/build/src/gf.c:2247 [inlined]
jl_apply_generic at /buildworker/worker/package_linux64/build/src/gf.c:2429
#930 at ./client.jl:394
jfptr_YY.930_31132 at /home/aayush/.julia/sysimages/ohmyrepl.so (unknown line)
_jl_invoke at /buildworker/worker/package_linux64/build/src/gf.c:2247 [inlined]
jl_apply_generic at /buildworker/worker/package_linux64/build/src/gf.c:2429
jl_apply at /buildworker/worker/package_linux64/build/src/julia.h:1788 [inlined]
jl_f__call_latest at /buildworker/worker/package_linux64/build/src/builtins.c:757
#invokelatest#2 at ./essentials.jl:716 [inlined]
invokelatest at ./essentials.jl:714 [inlined]
run_main_repl at ./client.jl:379
exec_options at ./client.jl:309
_start at ./client.jl:495
jfptr__start_38971 at /home/aayush/.julia/sysimages/ohmyrepl.so (unknown line)
_jl_invoke at /buildworker/worker/package_linux64/build/src/gf.c:2247 [inlined]
jl_apply_generic at /buildworker/worker/package_linux64/build/src/gf.c:2429
jl_apply at /buildworker/worker/package_linux64/build/src/julia.h:1788 [inlined]
true_main at /buildworker/worker/package_linux64/build/src/jlapi.c:559
jl_repl_entrypoint at /buildworker/worker/package_linux64/build/src/jlapi.c:701
main at julia (unknown line)
__libc_start_main at /usr/lib/libc.so.6 (unknown line)
unknown function (ip: 0x400808)
Allocations: 9459103 (Pool: 9455476; Big: 3627); GC: 8
gbaraldi commented 2 years ago

Probably should be some checking in or around https://github.com/JuliaGraphs/StaticGraphs.jl/blob/e15ade50f287295e92905c3b47e5a16125c36dcb/src/StaticGraphs.jl#L64-L68