From 80ffd2a83602d4b404024038d96d18dd5219ffc4 Mon Sep 17 00:00:00 2001 From: quinnj Date: Tue, 2 Jan 2018 07:47:19 -0700 Subject: [PATCH] Modify jl_nth_union_component to be more robust in the case of trying to get an invalid 'n'. This can happen if a struct or array containing Unions gets allocated using 'uninitialized' memory and the corresponding union selector bytes may contain arbitrary values. In these cases, we always know that u->a (where 'u' is a Union type) is a valid, non-Union type, so just return that instead. Fixes #25310 --- src/jltypes.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/jltypes.c b/src/jltypes.c index d8830d34c7589..ee05757e9e41b 100644 --- a/src/jltypes.c +++ b/src/jltypes.c @@ -367,7 +367,12 @@ static jl_value_t *nth_union_component(jl_value_t *v, int *pi) jl_value_t *jl_nth_union_component(jl_value_t *v, int i) { - return nth_union_component(v, &i); + jl_value_t *ret = nth_union_component(v, &i); + if (!ret) { + jl_uniontype_t *u = (jl_uniontype_t *)v; + return u->a; + } + return ret; } // inverse of jl_nth_union_component