Bug #12923
closed
Accessing singleton_class of fstring cause assertion failure
Added by naruse (Yui NARUSE) about 8 years ago.
Updated over 7 years ago.
Description
以下のワンライナーが「Assertion Failed: string.c:343:register_fstring:RBASIC_CLASS(ret) == rb_cString」します。
./miniruby -e'#encoding:us-ascii' -e'ObjectSpace.each_object{|o| o.singleton_class if o.is_a?(String)}; "hoge".intern'
クラッシュログは自分で走らせてもらうとして、何が起きているかというと、
(1) 文字列リテラルをはじめとして、何らかのかたちでシンボルを作らずにrb_fstringからfrozenなStringを作る
(2) その文字列に対してsingleton_classを呼ぶ。するとそのRVALUE->klassにsingleton_classが代入される
(3) 同じ内容の文字列でString#internする(1.でシンボルを作っているとlookup_str_sym()にひっかかる)
(4) register_fstringの"assert(RBASIC_CLASS(ret) == rb_cString);"で落ちる
しかし、どう直しましょうかね。
- Related to Bug #11386: taint flag about rb_fstring() added
RBASIC_CLASS
をrb_obj_class
にしてassertionを緩めましょうか。
- Status changed from Open to Closed
Applied in changeset r56747.
class.c: no fstring singleton class
- class.c (singleton_class_of): prohibit fstrings from creating
singleton classes.
temporary measure for [ruby-dev:49867] [Bug #12923]
- Status changed from Closed to Assigned
- Assignee set to matz (Yukihiro Matsumoto)
ひとまずSEGVはしないようにfstringはsingleton classを作れないようにします。
笹田さんと話したのですが、frozen object全般でsingleton classの追加を禁止したほうがよさそうという結論になりました。
まつもとさんはどうでしょうか。
- Status changed from Assigned to Closed
Applied in changeset r56754.
test_fstring.rb: fix exception
- test/-ext-/string/test_fstring.rb (test_singleton_class): fix
expected exception class. [ruby-dev:49867] [Bug #12923]
- Related to Bug #12930: instance_eval, instance_exec raises TypeError on a frozen String added
- Backport changed from 2.1: UNKNOWN, 2.2: UNKNOWN, 2.3: UNKNOWN to 2.2: DONTNEED, 2.3: REQUIRED, 2.4: DONTNEED
- Backport changed from 2.2: DONTNEED, 2.3: REQUIRED, 2.4: DONTNEED to 2.2: DONTNEED, 2.3: WONTFIX, 2.4: DONTNEED
- Backport changed from 2.2: DONTNEED, 2.3: WONTFIX, 2.4: DONTNEED to 2.2: DONTNEED, 2.3: REQUIRED, 2.4: REQUIRED
- Backport changed from 2.2: DONTNEED, 2.3: REQUIRED, 2.4: REQUIRED to 2.2: DONTNEED, 2.3: DONE, 2.4: REQUIRED
ruby_2_3 r58157 merged revision(s) 56747,56754,56777.
- Backport changed from 2.2: DONTNEED, 2.3: DONE, 2.4: REQUIRED to 2.2: DONTNEED, 2.3: DONE, 2.4: DONTNEED
Also available in: Atom
PDF
Like0
Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0