Skip to content

Commit b9e4274

Browse files
authored
fix potential null deref in merge_vararg_unions (#59525)
so as to avoid segfaults in the following type normalization ``` julia> Union{ Tuple{}, Tuple{Int}, Tuple{UInt}, Tuple{UInt, Vararg{UInt}}, Tuple{Int, Int, Vararg{Int}} }; [89686] signal 11 (2): Segmentation fault: 11 in expression starting at REPL[2]:1 jl_is_tuple_type at /Users/julia/.julia/scratchspaces/a66863c6-20e8-4ff4-8a62-49f30b1f605e/agent-cache/default-honeycrisp-XG3Q6T6R70.0/build/default-honeycrisp-XG3Q6T6R70-0/julialang/julia-master/src/./julia.h:1835 [inlined] merge_vararg_unions at /Users/julia/.julia/scratchspaces/a66863c6-20e8-4ff4-8a62-49f30b1f605e/agent-cache/default-honeycrisp-XG3Q6T6R70.0/build/default-honeycrisp-XG3Q6T6R70-0/julialang/julia-master/src/jltypes.c:617 ijl_type_union at /Users/julia/.julia/scratchspaces/a66863c6-20e8-4ff4-8a62-49f30b1f605e/agent-cache/default-honeycrisp-XG3Q6T6R70.0/build/default-honeycrisp-XG3Q6T6R70-0/julialang/julia-master/src/jltypes.c:674 jl_apply at /Users/julia/.julia/scratchspaces/a66863 ```
1 parent 8581930 commit b9e4274

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

src/jltypes.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -614,7 +614,7 @@ STATIC_INLINE void merge_vararg_unions(jl_value_t **temp, size_t nt)
614614
size_t min_elements = nfields-1;
615615
for (long j = i-1; j >= 0; j--) {
616616
jl_value_t *ttj = temp[j];
617-
if (!jl_is_tuple_type(ttj)) break;
617+
if (!(ttj && jl_is_tuple_type(ttj))) break;
618618
size_t nfieldsj = jl_nparams(ttj);
619619
if (nfieldsj >= min_elements) continue;
620620
if (nfieldsj != min_elements-1) break;

test/subtype.jl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,13 @@ function test_2()
6868
@test !(Tuple{Int,Vararg{Int,2}} <: Tuple{Int,Int,Int,Vararg{Int,1}})
6969
@test Tuple{Int,Vararg{Int}} == Tuple{Int,Vararg{Int}}
7070
@test (@UnionAll N Tuple{Int,Vararg{Int,N}}) == (@UnionAll N Tuple{Int,Vararg{Int,N}})
71+
@test Union{Tuple{}, Tuple{Int}, Tuple{UInt}} <: Union{
72+
Tuple{},
73+
Tuple{Int},
74+
Tuple{UInt},
75+
Tuple{UInt, Vararg{UInt}},
76+
Tuple{Int, Int, Vararg{Int}}
77+
}
7178

7279
@test issub_strict(Tuple{Tuple{Int,Int},Tuple{Int,Int}}, Tuple{NTuple{N,Int},NTuple{N,Int}} where N)
7380
@test !issub(Tuple{Tuple{Int,Int},Tuple{Int,}}, Tuple{NTuple{N,Int},NTuple{N,Int}} where N)

0 commit comments

Comments
 (0)