Skip to content

Commit dd1ed17

Browse files
authored
Add boundscheck in speccache_eq to avoid OOB access due to data race (JuliaLang#54840)
Like JuliaLang#54671, but for `speccache_eq`. Saw another segfault with this in the stack trace, hence this fix. I also looked for other uses of `jl_smallintset_lookup` and there's one in `idset.c`. That doesn't appear to be racy but I'm not familiar with the code, so maybe you can take a look at it in case we need to push a fix for that one too @gbaraldi or @vtjnash?
1 parent b0b7a85 commit dd1ed17

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

src/gf.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ static int8_t jl_cachearg_offset(jl_methtable_t *mt)
113113

114114
static uint_t speccache_hash(size_t idx, jl_value_t *data)
115115
{
116-
jl_method_instance_t *ml = (jl_method_instance_t*)jl_svecref(data, idx);
116+
jl_method_instance_t *ml = (jl_method_instance_t*)jl_svecref(data, idx); // This must always happen inside the lock
117117
jl_value_t *sig = ml->specTypes;
118118
if (jl_is_unionall(sig))
119119
sig = jl_unwrap_unionall(sig);
@@ -122,6 +122,8 @@ static uint_t speccache_hash(size_t idx, jl_value_t *data)
122122

123123
static int speccache_eq(size_t idx, const void *ty, jl_value_t *data, uint_t hv)
124124
{
125+
if (idx >= jl_svec_len(data))
126+
return 0; // We got a OOB access, probably due to a data race
125127
jl_method_instance_t *ml = (jl_method_instance_t*)jl_svecref(data, idx);
126128
jl_value_t *sig = ml->specTypes;
127129
if (ty == sig)

0 commit comments

Comments
 (0)