Thanks to visit codestin.com
Credit goes to bugs.ruby-lang.org

Project

General

Profile

Actions

Bug #22019

open

Set#intersect () segv if the block is called after return

Bug #22019: Set#intersect () segv if the block is called after return

Added by jhawthorn (John Hawthorn) 11 days ago.

Status:
Open
Target version:
-
[ruby-core:125389]

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).


Related issues 1 (0 open1 closed)

Related to Ruby - Bug #5801: Enumerable#take_while の proc を外に出して使うと SegvClosedActions

Updated by jhawthorn (John Hawthorn) 11 days ago Actions #1

  • Related to Bug #5801: Enumerable#take_while の proc を外に出して使うと Segv added
Actions

Also available in: PDF Atom