Skip to content

Commit 54e1119

Browse files
kpamnanyKristofferC
authored andcommitted
Add boundscheck in speccache_eq to avoid OOB access due to data race (#54840)
Like #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? (cherry picked from commit dd1ed17)
1 parent 2a53722 commit 54e1119

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
@@ -112,7 +112,7 @@ static int8_t jl_cachearg_offset(jl_methtable_t *mt)
112112

113113
static uint_t speccache_hash(size_t idx, jl_svec_t *data)
114114
{
115-
jl_method_instance_t *ml = (jl_method_instance_t*)jl_svecref(data, idx);
115+
jl_method_instance_t *ml = (jl_method_instance_t*)jl_svecref(data, idx); // This must always happen inside the lock
116116
jl_value_t *sig = ml->specTypes;
117117
if (jl_is_unionall(sig))
118118
sig = jl_unwrap_unionall(sig);
@@ -121,6 +121,8 @@ static uint_t speccache_hash(size_t idx, jl_svec_t *data)
121121

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

0 commit comments

Comments
 (0)