Actions
Bug #22019
openSet#intersect () segv if the block is called after return
Bug #22019:
Set#intersect () segv if the block is called after return
Description
class C
include Enumerable
def each(&b)
$b = b
yield 1
end
end
Set[1, 2, 3] & C.new
$b.call(1) # [BUG] Segmentation fault at 0x00007f21bfa67f60
The cause is essentially the same as #5801, we're initializing an ifunc pointing to a stack-allocated struct. The solution I think is to only ever use rb_block_call with a GC managed object like an imemo_memo.
In addition to set_intersection_block this likely also affects, lazy_flat_map_i, nmin_i, enum_sum_i, and product_each_i all of which are passed a stack buffer.
It might also be helpful to prevent the ifunc from being called after return. Some iterators (ex. sort_by) will raise a runtime error when this happens, but it's done ad-hoc (and detection depends on the variable still being accessible).
Updated by jhawthorn (John Hawthorn) 11 days ago
- Related to Bug #5801: Enumerable#take_while の proc を外に出して使うと Segv added
Actions