You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We pass a visited_type_ids HashSet into a bunch of functions during validation of metadata. The point of this is to spot when we are recursing into the same type ID we've already seen, and insetad of getting stuck in an infintie loop, returning some "magic" hash.
The problem is that we reuse this visited_type_ids when hashing multiple types in some cases, so eg if we hash the types:
Ie, we hash Foo without any issues, but then when we try to hash Bar and Wibble reusing visited_type_ids, we have seen both types already and so both get replaced with some constant RECURSIVE_HASH to avoid infinite loops.
The solution is to ensure that visited_ids is not reused across type hashings at all.
One way to help ensure this is to make it so that get_type_hash does not take visited_ids as an argument and instead creates it internally. It then internally will call get_type_def_hash and whatever by passing this new visited_ids in, and anything needing to recusviely call get_type_hash again can call some inner get_type_hash_recursive call or something which does accept visited_ids and is not exposed/available for anything else to call.
With that, every attempt to hash a type will atuomatically use a new internal "recursive ids set" and we'll prevent accidental re-use.
We pass a
visited_type_ids
HashSet into a bunch of functions during validation of metadata. The point of this is to spot when we are recursing into the same type ID we've already seen, and insetad of getting stuck in an infintie loop, returning some "magic" hash.The problem is that we reuse this
visited_type_ids
when hashing multiple types in some cases, so eg if we hash the types:We end up with a hashing approach something like:
Ie, we hash
Foo
without any issues, but then when we try to hashBar
andWibble
reusingvisited_type_ids
, we have seen both types already and so both get replaced with some constantRECURSIVE_HASH
to avoid infinite loops.The solution is to ensure that
visited_ids
is not reused across type hashings at all.One way to help ensure this is to make it so that
get_type_hash
does not takevisited_ids
as an argument and instead creates it internally. It then internally will callget_type_def_hash
and whatever by passing this newvisited_ids
in, and anything needing to recusviely callget_type_hash
again can call some innerget_type_hash_recursive
call or something which does acceptvisited_ids
and is not exposed/available for anything else to call.With that, every attempt to hash a type will atuomatically use a new internal "recursive ids set" and we'll prevent accidental re-use.
See #1041 (comment) for a bit of context
The text was updated successfully, but these errors were encountered: