Repository navigation
mruby-objectspace-weakmap: hide WeakKeyMap's values from ObjectSpace - #7841
Conversation
WeakKeyMap indexes the Array of its values by entry position without checking its length, in #[], #delete, #clear and the GC's wm_clear_dead(). ObjectSpace.each_object(Array) could find that Array, and shrinking it had those reads and writes go past its end.
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
ASan (clang, full-core gembox),
GC.startafter shrinking the values Array of a WeakKeyMap:WeakKeyMap#deleteon such a map reads past the end first (heap-buffer-overflow READ inwm_value_at, weakmap.c:224).WeakKeyMap keeps its values in an Array under an instance variable Ruby cannot name, and
wm_value_at(),wm_drop()andwm_reserve()index it by entry position without checking its length.ObjectSpace.each_object(Array)still yields that Array, so Ruby can find it and shrink it:wm_vals_new()now clears the Array's class pointer, as the core does for its own internal arrays and strings, soObjectSpace.each_objectskips it. Nothing in the gem reads the Array's class.Validation: the new test in
test/weakmap.rb(mruby-objectspace added as a test dependency) aborts mrbtest on master and passes with the fix. Full clang ASan mrbtest with-s: 3560 total, KO 0, Crash 0.Summary by CodeRabbit