Skip to content

Commit

Permalink
Add boundscheck in speccache_eq to avoid OOB access due to data race (#…
Browse files Browse the repository at this point in the history
…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?
  • Loading branch information
kpamnany authored Jun 18, 2024
1 parent b0b7a85 commit dd1ed17
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/gf.c
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ static int8_t jl_cachearg_offset(jl_methtable_t *mt)

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

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

0 comments on commit dd1ed17

Please sign in to comment.