Project

General

Profile

Actions

Bug #20042

closed

ObjectSpace finalizer can cause segfault

Added by ioquatix (Samuel Williams) 5 months ago. Updated 3 months ago.

Status:
Closed
Target version:
-
[ruby-core:115594]

Description

class Finalizer
  def call # <- missing (id) argument
  end
end

object = Object.new
ObjectSpace.define_finalizer(object, Finalizer.new)
object = nil

GC.start # segfaults here
Actions #1

Updated by ioquatix (Samuel Williams) 5 months ago

  • Description updated (diff)

Updated by byroot (Jean Boussier) 5 months ago

  • Backport changed from 3.0: UNKNOWN, 3.1: UNKNOWN, 3.2: UNKNOWN to 3.0: DONTNEED, 3.1: REQUIRED, 3.2: REQUIRED

It started on 3.1:

:ok: 1.8 -- 3.0
(no stdout :speak_no_evil:)
:ok: 3.1,3.2
<internal:gc>:34: warning: Exception in finalizer #<Method: Object#fin() -:2>
-:2:in `fin': wrong number of arguments (given 1, expected 0) (ArgumentError)
    from <internal:gc>:34:in `call'
    from <internal:gc>:34:in `start'
    from -:7:in `<main>'


:ok: 7e05e9ff94 (2023-12-06T06:48:55Z)
<internal:gc>:39: warning: Exception in finalizer #<Method: Object#fin() -:2>
-:2:in `fin': wrong number of arguments (given 1, expected 0) (ArgumentError)
    from <internal:gc>:39:in `call'
    from <internal:gc>:39:in `start'
    from -:7:in `<main>'

Updated by byroot (Jean Boussier) 5 months ago

Actually nevermind, my simplification was wrong. Using exactly your script, it crash all the way to 3.0.

:x: 3.0
```<internal:gc>:35: [BUG] Stack consistency error (sp: 17, bp: 15)
ruby 3.0.5p211 (2022-11-24 revision ba5cf0f7c5) [x86_64-linux]
-- Control frame information -----------------------------------------------
c:0003 p:0011 s:0017 e:000014 METHOD <internal:gc>:35
c:0002 p:0060 s:0007 E:001af8 EVAL   -:10 [FINISH]
c:0001 p:0000 s:0003 E:002140 (none) [FINISH]
-- Ruby level backtrace information ----------------------------------------


:x: 3.1
<internal:gc>:34: warning: Exception in finalizer #<Finalizer:0x00007fc730f72e30>
-:2:in `call': wrong number of arguments (given 1, expected 0) (ArgumentError)
    from <internal:gc>:34:in `start'
    from -:10:in `<main>'
<internal:gc>:35:in `start': Stack consistency error (sp: 17, bp: 15) (fatal)

:x: 3.2
```<internal:gc>:34: warning: Exception in finalizer #<Finalizer:0x00007fe950ab9d98>
-:2:in `call': wrong number of arguments (given 1, expected 0) (ArgumentError)
    from <internal:gc>:34:in `start'
    from -:10:in `<main>'
<internal:gc>:35: [BUG] Stack consistency error (sp: 17, bp: 15)


:x: 7e05e9ff94 (2023-12-06T06:48:55Z)
```<internal:gc>:39: warning: Exception in finalizer #<Finalizer:0x00007fae4e314850>
-:2:in `call': wrong number of arguments (given 1, expected 0) (ArgumentError)
    from <internal:gc>:39:in `start'
    from -:10:in `<main>'
<internal:gc>:40: [BUG] Stack consistency error (sp: 17, bp: 15)

Actions #4

Updated by byroot (Jean Boussier) 5 months ago

  • Backport changed from 3.0: DONTNEED, 3.1: REQUIRED, 3.2: REQUIRED to 3.0: REQUIRED, 3.1: REQUIRED, 3.2: REQUIRED
Actions #5

Updated by ko1 (Koichi Sasada) 4 months ago

  • Status changed from Open to Closed

Applied in changeset git|f9a48548cf3ef54fc0a385ccd78c708737055ecc.


restore the stack pointer on finalizer

When error on finalizer, the exception will be ignored.
To restart the code, we need to restore the stack pointer.

fix [Bug #20042]

Updated by nagachika (Tomoyuki Chikanaga) 3 months ago

  • Backport changed from 3.0: REQUIRED, 3.1: REQUIRED, 3.2: REQUIRED to 3.0: REQUIRED, 3.1: REQUIRED, 3.2: DONE

ruby_3_2 0cc0e43745ffc13a596441adccee295274d99a0b merged revision(s) f9a48548cf3ef54fc0a385ccd78c708737055ecc.

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0