Project

General

Profile

Actions

Bug #19173

closed

syntax_suggest segfaults on syntax error when refinement activated

Added by tomstuart (Tom Stuart) almost 2 years ago. Updated almost 2 years ago.

Status:
Closed
Assignee:
-
Target version:
ruby -v:
ruby 3.2.0dev (2022-12-02T10:47:18Z master 11871e49c4) [arm64-darwin21]
[ruby-core:111155]

Description

While reporting certain syntax errors (e.g. “Invalid yield”, “Invalid redo”), syntax_suggest segfaults when a refinement is activated:

% echo 'yield' > test.rb; ruby test.rb
test.rb:1: Invalid yield
test.rb: compile error (SyntaxError)

% echo 'using Module.new; yield' > test.rb; ruby test.rb
test.rb:1: Invalid yield
/Users/tom/.rubies/ruby-master/lib/ruby/3.2.0+3/fileutils.rb:2646: [BUG] Segmentation fault at 0x0000000000000008
[…]
-- Ruby level backtrace information ----------------------------------------
/Users/tom/.rubies/ruby-master/lib/ruby/3.2.0+3/syntax_suggest/core_ext.rb:25:in `detailed_message'

There’s no problem if syntax_suggest is disabled:

% echo 'using Module.new; yield' > test.rb; ruby --disable-syntax_suggest test.rb
test.rb:1: Invalid yield
test.rb: compile error (SyntaxError)

This bug exists on both 3.2.0-preview3 and master, and I’ve verified it on x86_64 as well as my arm64 machine. A crash report log is attached.


Files

ruby-2022-12-02-122013.ips (16.4 KB) ruby-2022-12-02-122013.ips tomstuart (Tom Stuart), 12/02/2022 12:35 PM
Actions #1

Updated by byroot (Jean Boussier) almost 2 years ago

  • Backport changed from 2.7: UNKNOWN, 3.0: UNKNOWN, 3.1: UNKNOWN to 2.7: DONTNEED, 3.0: DONTNEED, 3.1: DONTNEED
Actions #2

Updated by byroot (Jean Boussier) almost 2 years ago

  • Target version set to 3.2

Updated by schneems (Richard Schneeman) almost 2 years ago

Line 25 is the require which seems odd https://github.com/ruby/ruby/blob/85a1c67a6550641e5de96cdbee1713be3f1e8882/lib/syntax_suggest/core_ext.rb#L25

I’ll try to reproduce when I get back to my computer.

Updated by ufuk (Ufuk Kayserilioglu) almost 2 years ago

@schneems (Richard Schneeman) This seems to be less about syntax suggest than refinements. @tenderlovemaking (Aaron Patterson) already has a PR up that should fix it: https://github.com/ruby/ruby/pull/6853

Actions #5

Updated by tenderlovemaking (Aaron Patterson) almost 2 years ago

  • Status changed from Open to Closed

Applied in changeset git|dba61f487cd7c1555f1187a2e2846506c1b143be.


return early if there is no is_entries buffer

If there is a compilation error, is_entries may not be allocated, but
ic_size could be greater than 0. If we don't have a buffer to iterate
over, just return early. Otherwise GC could segv

[Bug #19173]

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0