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

[BUG] OhMyREPL triggers segmentation fault in Julia 1.11 #376

Closed
ogauthe opened this issue Jan 28, 2025 · 6 comments
Closed

[BUG] OhMyREPL triggers segmentation fault in Julia 1.11 #376

ogauthe opened this issue Jan 28, 2025 · 6 comments

Comments

@ogauthe
Copy link

ogauthe commented Jan 28, 2025

Hi! I found this code to generate a segfault when using OhMyREPL and Julia 1.11. Running with Julia 1.10 is fine.
I commented out my startup.jl, the whole code is here. Commenting the first line removes the issue.

using OhMyREPL

struct Foo end

Base.length(::Foo) = 3

struct SectorUnitRange{T,Sector,Range<:AbstractUnitRange{T}} <: AbstractUnitRange{T}
  sector::Sector
  r::Range
  offset::T

  function SectorUnitRange(s, r, offset)
    return new{eltype(r),typeof(s),typeof(r)}(s, r, offset)
  end
end

# accessors
sector(sr::SectorUnitRange) = sr.sector
Base.range(sr::SectorUnitRange) = sr.r
Base.first(sr::SectorUnitRange) = sr.offset

# Base interface
Base.length(sr::SectorUnitRange) = length(sector(sr)) * length(range(sr))

Base.iterate(sr::SectorUnitRange) = iterate(first(sr):last(sr))
Base.iterate(sr::SectorUnitRange, i::Integer) = iterate(first(sr):last(sr), i)

Base.last(sr::SectorUnitRange) = first(sr) + length(sr)

sr = SectorUnitRange(Foo(), 1:1, 3)
println("Crash here for Julia 1.11 while using OhMyREPL")
@show collect(sr)
[1843714] signal 11 (1): Segmentation fault
in expression starting at /mnt/home/ogauthe/Documents/itensor/KroneckerProducts.jl/src/minimal.jl:33
jl_gc_pool_alloc_inner at /cache/build/builder-demeter6-3/julialang/julia-release-1-dot-11/src/gc.c:1334
jl_gc_pool_alloc_noinline at /cache/build/builder-demeter6-3/julialang/julia-release-1-dot-11/src/gc.c:1391 [inlined]
jl_gc_alloc_ at /cache/build/builder-demeter6-3/julialang/julia-release-1-dot-11/src/julia_internal.h:523 [inlined]
jl_gc_alloc at /cache/build/builder-demeter6-3/julialang/julia-release-1-dot-11/src/gc.c:3951
_new_genericmemory_ at /cache/build/builder-demeter6-3/julialang/julia-release-1-dot-11/src/genericmemory.c:56 [inlined]
jl_alloc_genericmemory at /cache/build/builder-demeter6-3/julialang/julia-release-1-dot-11/src/genericmemory.c:99
GenericMemory at ./boot.jl:516 [inlined]
Array at ./boot.jl:578 [inlined]
getindex at ./array.jl:417
jl_apply at /cache/build/builder-demeter6-3/julialang/julia-release-1-dot-11/src/julia.h:2157 [inlined]
do_apply at /cache/build/builder-demeter6-3/julialang/julia-release-1-dot-11/src/builtins.c:831
most_general_argtypes at ./compiler/inferenceresult.jl:117
most_general_argtypes at ./compiler/inferenceresult.jl:115 [inlined]
matching_cache_argtypes at ./compiler/inferenceresult.jl:27
InferenceResult at ./compiler/types.jl:99 [inlined]
typeinf_ext at ./compiler/typeinfer.jl:1098
typeinf_ext_toplevel at ./compiler/typeinfer.jl:1139
typeinf_ext_toplevel at ./compiler/typeinfer.jl:1135
jfptr_typeinf_ext_toplevel_39915.1 at /mnt/home/ogauthe/.julia/juliaup/julia-1.11.3+0.x64.linux.gnu/lib/julia/sys.so (unknown line)
jl_apply at /cache/build/builder-demeter6-3/julialang/julia-release-1-dot-11/src/julia.h:2157 [inlined]
jl_type_infer at /cache/build/builder-demeter6-3/julialang/julia-release-1-dot-11/src/gf.c:390
jl_generate_fptr_impl at /cache/build/builder-demeter6-3/julialang/julia-release-1-dot-11/src/jitlayers.cpp:519
jl_compile_method_internal at /cache/build/builder-demeter6-3/julialang/julia-release-1-dot-11/src/gf.c:2536 [inlined]
jl_compile_method_internal at /cache/build/builder-demeter6-3/julialang/julia-release-1-dot-11/src/gf.c:2423
_jl_invoke at /cache/build/builder-demeter6-3/julialang/julia-release-1-dot-11/src/gf.c:2940 [inlined]
ijl_apply_generic at /cache/build/builder-demeter6-3/julialang/julia-release-1-dot-11/src/gf.c:3125
jl_apply at /cache/build/builder-demeter6-3/julialang/julia-release-1-dot-11/src/julia.h:2157 [inlined]
do_call at /cache/build/builder-demeter6-3/julialang/julia-release-1-dot-11/src/interpreter.c:126
eval_value at /cache/build/builder-demeter6-3/julialang/julia-release-1-dot-11/src/interpreter.c:223
eval_stmt_value at /cache/build/builder-demeter6-3/julialang/julia-release-1-dot-11/src/interpreter.c:174 [inlined]
eval_body at /cache/build/builder-demeter6-3/julialang/julia-release-1-dot-11/src/interpreter.c:663
jl_interpret_toplevel_thunk at /cache/build/builder-demeter6-3/julialang/julia-release-1-dot-11/src/interpreter.c:821
jl_toplevel_eval_flex at /cache/build/builder-demeter6-3/julialang/julia-release-1-dot-11/src/toplevel.c:943
jl_toplevel_eval_flex at /cache/build/builder-demeter6-3/julialang/julia-release-1-dot-11/src/toplevel.c:886
ijl_toplevel_eval_in at /cache/build/builder-demeter6-3/julialang/julia-release-1-dot-11/src/toplevel.c:994
eval at ./boot.jl:430 [inlined]
include_string at ./loading.jl:2734
_include at ./loading.jl:2794
include at ./Base.jl:557
jfptr_include_46888.1 at /mnt/home/ogauthe/.julia/juliaup/julia-1.11.3+0.x64.linux.gnu/lib/julia/sys.so (unknown line)
exec_options at ./client.jl:323
_start at ./client.jl:531
jfptr__start_73609.1 at /mnt/home/ogauthe/.julia/juliaup/julia-1.11.3+0.x64.linux.gnu/lib/julia/sys.so (unknown line)
jl_apply at /cache/build/builder-demeter6-3/julialang/julia-release-1-dot-11/src/julia.h:2157 [inlined]
true_main at /cache/build/builder-demeter6-3/julialang/julia-release-1-dot-11/src/jlapi.c:900
jl_repl_entrypoint at /cache/build/builder-demeter6-3/julialang/julia-release-1-dot-11/src/jlapi.c:1059
main at /cache/build/builder-demeter6-3/julialang/julia-release-1-dot-11/cli/loader_exe.c:58
__libc_start_main at /lib64/libc.so.6 (unknown line)
unknown function (ip: 0x4010b8)
Allocations: 1937142 (Pool: 1937051; Big: 91); GC: 3
Segmentation fault (core dumped)

Julia v"1.11.3"
OhMyREPL v0.5.28
additional version info:

Julia Version 1.11.3
Commit d63adeda50d (2025-01-21 19:42 UTC)
Build Info:
  Official https://julialang.org/ release
Platform Info:
  OS: Linux (x86_64-linux-gnu)
  CPU: 32 × Intel(R) Xeon(R) Gold 6244 CPU @ 3.60GHz
  WORD_SIZE: 64
  LLVM: libLLVM-16.0.6 (ORCJIT, cascadelake)
Threads: 4 default, 0 interactive, 2 GC (on 32 virtual cores)
Environment:
  LD_LIBRARY_PATH = /mnt/sw/nix/store/71ksmx7k6xy3v9ksfkv5mp5kxxp64pd6-python-3.10.13-view/lib:/mnt/sw/nix/store/kkhxdzyg5kaxrxrl6j7pwapq7v7xacc7-openblas-0.3.26/lib
  JULIA_NUM_THREADS = 4
@Moelf
Copy link
Collaborator

Moelf commented Jan 28, 2025

it really crashed at printing, somehow, but println() doesn't crash it, display() also doesn't crash it.

@ogauthe
Copy link
Author

ogauthe commented Jan 28, 2025

it really crashed at printing, somehow, but println() doesn't crash it, display() also doesn't crash it.

Indeed. Also, adding a line @show collect(1:1) before the last line avoids the crash.

@KristofferC
Copy link
Owner

Running with bounds checking enabled I get:

julia> @show collect(sr)
ERROR: BoundsError: attempt to access 3-element Vector{Int64} at index [4]
Stacktrace:
 [1] throw_boundserror(A::Vector{Int64}, I::Tuple{Int64})
   @ Base .\essentials.jl:14
 [2] setindex!
   @ .\array.jl:986 [inlined]
 [3] Array
   @ .\range.jl:1375 [inlined]
 [4] Array
   @ .\boot.jl:605 [inlined]
 [5] collect(r::SectorUnitRange{Int64, Foo, UnitRange{Int64}})
   @ Base .\range.jl:1380
 [6] macro expansion
   @ show.jl:1232 [inlined]
 [7] top-level scope
   @ REPL[16]:1

By default you will just get memory corruption and whether it segfaults or not is unpredictable but the root cause is not OhMyREPL.

@KristofferC KristofferC closed this as not planned Won't fix, can't repro, duplicate, stale Jan 29, 2025
@Moelf
Copy link
Collaborator

Moelf commented Jan 29, 2025

By default you will just get memory corruption and whether

what does this mean -- I don't see any @inbounds in the original snippet. Normally erroring out is a lot better than segfault I think

@KristofferC
Copy link
Owner

I don't see any @inbounds in the original snippet

The @inbounds is in the collect implementation in Base. Right now, you have to get Base.length right or you risk memory corruption as shown here.

@KristofferC
Copy link
Owner

Here is the upstream issue: JuliaLang/julia#41214

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants