Project

General

Profile

Bug #13037

Segmentation fault on "\n".lines(chomp: true)

Added by asterite (Ary Borenszweig) almost 3 years ago. Updated almost 3 years ago.

Status:
Closed
Priority:
Normal
Assignee:
-
Target version:
-
ruby -v:
ruby 2.4.0dev (2016-12-15 trunk 57084) [x86_64-darwin15]
[ruby-core:78660]

Description

$ irb
irb(main):001:0> RUBY_DESCRIPTION
=> "ruby 2.4.0dev (2016-12-15 trunk 57084) [x86_64-darwin15]"
irb(main):002:0> "\n".lines(chomp: true)
(irb):2: [BUG] Segmentation fault at 0x00000000000000
ruby 2.4.0dev (2016-12-15 trunk 57084) [x86_64-darwin15]

-- Crash Report log information --------------------------------------------
See Crash Report log file under the one of following:

* ~/Library/Logs/CrashReporter

* /Library/Logs/CrashReporter

* ~/Library/Logs/DiagnosticReports

* /Library/Logs/DiagnosticReports

for more details.

Don't forget to include the above Crash Report log file in bug reports.

-- Control frame information -----------------------------------------------
c:0020 p:---- s:0100 e:000099 CFUNC :lines
c:0019 p:0009 s:0095 e:000094 EVAL (irb):2 [FINISH]
c:0018 p:---- s:0092 e:000091 CFUNC :eval
c:0017 p:0025 s:0084 e:000083 METHOD /Users/asterite-manas/.rbenv/versions/2.4.0-dev/lib/ruby/2.4.0/irb/workspace.rb:87
c:0016 p:0027 s:0076 e:000074 METHOD /Users/asterite-manas/.rbenv/versions/2.4.0-dev/lib/ruby/2.4.0/irb/context.rb:381
c:0015 p:0024 s:0069 e:000068 BLOCK /Users/asterite-manas/.rbenv/versions/2.4.0-dev/lib/ruby/2.4.0/irb.rb:493
c:0014 p:0041 s:0060 e:000059 METHOD /Users/asterite-manas/.rbenv/versions/2.4.0-dev/lib/ruby/2.4.0/irb.rb:627
c:0013 p:0011 s:0054 e:000053 BLOCK /Users/asterite-manas/.rbenv/versions/2.4.0-dev/lib/ruby/2.4.0/irb.rb:490
c:0012 p:0128 s:0049 e:000048 BLOCK /Users/asterite-manas/.rbenv/versions/2.4.0-dev/lib/ruby/2.4.0/irb/ruby-lex.rb:246 [FINISH]
c:0011 p:---- s:0045 e:000044 CFUNC :loop
c:0010 p:0009 s:0041 e:000040 BLOCK /Users/asterite-manas/.rbenv/versions/2.4.0-dev/lib/ruby/2.4.0/irb/ruby-lex.rb:232 [FINISH]
c:0009 p:---- s:0038 e:000037 CFUNC :catch
c:0008 p:0018 s:0033 e:000032 METHOD /Users/asterite-manas/.rbenv/versions/2.4.0-dev/lib/ruby/2.4.0/irb/ruby-lex.rb:231
c:0007 p:0037 s:0029 E:000bd0 METHOD /Users/asterite-manas/.rbenv/versions/2.4.0-dev/lib/ruby/2.4.0/irb.rb:489
c:0006 p:0008 s:0025 e:000024 BLOCK /Users/asterite-manas/.rbenv/versions/2.4.0-dev/lib/ruby/2.4.0/irb.rb:430 [FINISH]
c:0005 p:---- s:0022 e:000021 CFUNC :catch
c:0004 p:0075 s:0017 E:002148 METHOD /Users/asterite-manas/.rbenv/versions/2.4.0-dev/lib/ruby/2.4.0/irb.rb:429
c:0003 p:0118 s:0012 e:000011 METHOD /Users/asterite-manas/.rbenv/versions/2.4.0-dev/lib/ruby/2.4.0/irb.rb:385
c:0002 p:0023 s:0006 e:000005 EVAL /Users/asterite-manas/.rbenv/versions/2.4.0/bin/irb:11 [FINISH]
c:0001 p:0000 s:0003 E:001b00 (none) [FINISH]

-- Ruby level backtrace information ----------------------------------------
/Users/asterite-manas/.rbenv/versions/2.4.0/bin/irb:11:in <main>'
/Users/asterite-manas/.rbenv/versions/2.4.0-dev/lib/ruby/2.4.0/irb.rb:385:in
start'
/Users/asterite-manas/.rbenv/versions/2.4.0-dev/lib/ruby/2.4.0/irb.rb:429:in run'
/Users/asterite-manas/.rbenv/versions/2.4.0-dev/lib/ruby/2.4.0/irb.rb:429:in
catch'
/Users/asterite-manas/.rbenv/versions/2.4.0-dev/lib/ruby/2.4.0/irb.rb:430:in block in run'
/Users/asterite-manas/.rbenv/versions/2.4.0-dev/lib/ruby/2.4.0/irb.rb:489:in
eval_input'
/Users/asterite-manas/.rbenv/versions/2.4.0-dev/lib/ruby/2.4.0/irb/ruby-lex.rb:231:in each_top_level_statement'
/Users/asterite-manas/.rbenv/versions/2.4.0-dev/lib/ruby/2.4.0/irb/ruby-lex.rb:231:in
catch'
/Users/asterite-manas/.rbenv/versions/2.4.0-dev/lib/ruby/2.4.0/irb/ruby-lex.rb:232:in block in each_top_level_statement'
/Users/asterite-manas/.rbenv/versions/2.4.0-dev/lib/ruby/2.4.0/irb/ruby-lex.rb:232:in
loop'
/Users/asterite-manas/.rbenv/versions/2.4.0-dev/lib/ruby/2.4.0/irb/ruby-lex.rb:246:in block (2 levels) in each_top_level_statement'
/Users/asterite-manas/.rbenv/versions/2.4.0-dev/lib/ruby/2.4.0/irb.rb:490:in
block in eval_input'
/Users/asterite-manas/.rbenv/versions/2.4.0-dev/lib/ruby/2.4.0/irb.rb:627:in signal_status'
/Users/asterite-manas/.rbenv/versions/2.4.0-dev/lib/ruby/2.4.0/irb.rb:493:in
block (2 levels) in eval_input'
/Users/asterite-manas/.rbenv/versions/2.4.0-dev/lib/ruby/2.4.0/irb/context.rb:381:in evaluate'
/Users/asterite-manas/.rbenv/versions/2.4.0-dev/lib/ruby/2.4.0/irb/workspace.rb:87:in
evaluate'
/Users/asterite-manas/.rbenv/versions/2.4.0-dev/lib/ruby/2.4.0/irb/workspace.rb:87:in eval'
(irb):2:in
irb_binding'
(irb):2:in `lines'

-- Machine register context ------------------------------------------------
rax: 0x0000000000000000 rbx: 0x00007faf8a500d10 rcx: 0x00000000ffffffff
rdx: 0x0000000000000000 rdi: 0x0000000000000000 rsi: 0x00007faf8d8724e8
rbp: 0x00007fff58d4ceb0 rsp: 0x00007fff58d4ce80 r8: 0x000000010707a280
r9: 0x00007faf8a406ed0 r10: 0x0000000000000005 r11: 0xffffffffffffff10
r12: 0x00007faf8d8724e8 r13: 0x0000000000000000 r14: 0x00007faf8a500d10
r15: 0x00007faf8d8724e8 rip: 0x0000000106f07043 rfl: 0x0000000000010246

-- C level backtrace information -------------------------------------------
0 ruby 0x00000001070742eb rb_vm_bugreport + 379
1 ruby 0x0000000106f14604 rb_bug_context + 452
2 ruby 0x0000000106ff3c08 sigsegv + 72
3 libsystem_platform.dylib 0x00007fff929f352a _sigtramp + 26
4 ruby 0x0000000106f07043 rb_enc_ascget + 51
5 ruby 0x000000010701a30c rb_str_enumerate_lines + 1484
6 ruby 0x0000000107067ee5 vm_call_cfunc + 277
7 ruby 0x0000000107052a5d vm_exec_core + 11549
8 ruby 0x0000000107062c18 vm_exec + 120
9 ruby 0x0000000107070725 eval_string_with_cref + 1269
10 ruby 0x000000010705e622 rb_f_eval + 306
11 ruby 0x0000000107067ee5 vm_call_cfunc + 277
12 ruby 0x0000000107052a5d vm_exec_core + 11549
13 ruby 0x0000000107062c18 vm_exec + 120
14 ruby 0x000000010706f9f9 invoke_block_from_c_splattable + 345
15 ruby 0x0000000107070a5f loop_i + 31
16 ruby 0x0000000106f1def3 rb_rescue2 + 275
17 ruby 0x0000000107067ee5 vm_call_cfunc + 277
18 ruby 0x000000010705232b vm_exec_core + 9707
19 ruby 0x0000000107062c18 vm_exec + 120
20 ruby 0x000000010706f9f9 invoke_block_from_c_splattable + 345
21 ruby 0x00000001070709fa catch_i + 74
22 ruby 0x000000010705f85c vm_catch_protect + 156
23 ruby 0x000000010705ff42 rb_f_catch + 66
24 ruby 0x0000000107067ee5 vm_call_cfunc + 277
25 ruby 0x000000010705232b vm_exec_core + 9707
26 ruby 0x0000000107062c18 vm_exec + 120
27 ruby 0x000000010706f9f9 invoke_block_from_c_splattable + 345
28 ruby 0x00000001070709fa catch_i + 74
29 ruby 0x000000010705f85c vm_catch_protect + 156
30 ruby 0x000000010705ff42 rb_f_catch + 66
31 ruby 0x0000000107067ee5 vm_call_cfunc + 277
32 ruby 0x000000010705232b vm_exec_core + 9707
33 ruby 0x0000000107062c18 vm_exec + 120
34 ruby 0x0000000106f1d218 ruby_exec_internal + 136
35 ruby 0x0000000106f1d136 ruby_run_node + 54
36 ruby 0x0000000106eb0b7f main + 79

-- Other runtime information -----------------------------------------------

  • Loaded script: irb

  • Loaded features:

    0 enumerator.so
    1 thread.rb
    2 rational.so
    3 complex.so
    4 /Users/asterite-manas/.rbenv/versions/2.4.0-dev/lib/ruby/2.4.0/x86_64-darwin15/enc/encdb.bundle
    5 /Users/asterite-manas/.rbenv/versions/2.4.0-dev/lib/ruby/2.4.0/x86_64-darwin15/enc/trans/transdb.bundle
    6 /Users/asterite-manas/.rbenv/versions/2.4.0-dev/lib/ruby/2.4.0/unicode_normalize.rb
    7 /Users/asterite-manas/.rbenv/versions/2.4.0-dev/lib/ruby/2.4.0/x86_64-darwin15/rbconfig.rb
    8 /Users/asterite-manas/.rbenv/versions/2.4.0-dev/lib/ruby/2.4.0/rubygems/compatibility.rb
    9 /Users/asterite-manas/.rbenv/versions/2.4.0-dev/lib/ruby/2.4.0/rubygems/defaults.rb
    10 /Users/asterite-manas/.rbenv/versions/2.4.0-dev/lib/ruby/2.4.0/rubygems/deprecate.rb
    11 /Users/asterite-manas/.rbenv/versions/2.4.0-dev/lib/ruby/2.4.0/rubygems/errors.rb
    12 /Users/asterite-manas/.rbenv/versions/2.4.0-dev/lib/ruby/2.4.0/rubygems/version.rb
    13 /Users/asterite-manas/.rbenv/versions/2.4.0-dev/lib/ruby/2.4.0/rubygems/requirement.rb
    14 /Users/asterite-manas/.rbenv/versions/2.4.0-dev/lib/ruby/2.4.0/rubygems/platform.rb
    15 /Users/asterite-manas/.rbenv/versions/2.4.0-dev/lib/ruby/2.4.0/rubygems/basic_specification.rb
    16 /Users/asterite-manas/.rbenv/versions/2.4.0-dev/lib/ruby/2.4.0/rubygems/stub_specification.rb
    17 /Users/asterite-manas/.rbenv/versions/2.4.0-dev/lib/ruby/2.4.0/rubygems/util/list.rb
    18 /Users/asterite-manas/.rbenv/versions/2.4.0-dev/lib/ruby/2.4.0/x86_64-darwin15/stringio.bundle
    19 /Users/asterite-manas/.rbenv/versions/2.4.0-dev/lib/ruby/2.4.0/rubygems/specification.rb
    20 /Users/asterite-manas/.rbenv/versions/2.4.0-dev/lib/ruby/2.4.0/rubygems/exceptions.rb
    21 /Users/asterite-manas/.rbenv/versions/2.4.0-dev/lib/ruby/2.4.0/rubygems/dependency.rb
    22 /Users/asterite-manas/.rbenv/versions/2.4.0-dev/lib/ruby/2.4.0/rubygems/core_ext/kernel_gem.rb
    23 /Users/asterite-manas/.rbenv/versions/2.4.0-dev/lib/ruby/2.4.0/monitor.rb
    24 /Users/asterite-manas/.rbenv/versions/2.4.0-dev/lib/ruby/2.4.0/rubygems/core_ext/kernel_require.rb
    25 /Users/asterite-manas/.rbenv/versions/2.4.0-dev/lib/ruby/2.4.0/rubygems.rb
    26 /Users/asterite-manas/.rbenv/versions/2.4.0-dev/lib/ruby/2.4.0/rubygems/path_support.rb
    27 /Users/asterite-manas/.rbenv/versions/2.4.0-dev/lib/ruby/2.4.0/e2mmap.rb
    28 /Users/asterite-manas/.rbenv/versions/2.4.0-dev/lib/ruby/2.4.0/irb/init.rb
    29 /Users/asterite-manas/.rbenv/versions/2.4.0-dev/lib/ruby/2.4.0/irb/workspace.rb
    30 /Users/asterite-manas/.rbenv/versions/2.4.0-dev/lib/ruby/2.4.0/irb/inspector.rb
    31 /Users/asterite-manas/.rbenv/versions/2.4.0-dev/lib/ruby/2.4.0/irb/output-method.rb
    32 /Users/asterite-manas/.rbenv/versions/2.4.0-dev/lib/ruby/2.4.0/irb/context.rb
    33 /Users/asterite-manas/.rbenv/versions/2.4.0-dev/lib/ruby/2.4.0/irb/extend-command.rb
    34 /Users/asterite-manas/.rbenv/versions/2.4.0-dev/lib/ruby/2.4.0/irb/notifier.rb
    35 /Users/asterite-manas/.rbenv/versions/2.4.0-dev/lib/ruby/2.4.0/irb/slex.rb
    36 /Users/asterite-manas/.rbenv/versions/2.4.0-dev/lib/ruby/2.4.0/irb/ruby-token.rb
    37 /Users/asterite-manas/.rbenv/versions/2.4.0-dev/lib/ruby/2.4.0/irb/ruby-lex.rb
    38 /Users/asterite-manas/.rbenv/versions/2.4.0-dev/lib/ruby/2.4.0/irb/src_encoding.rb
    39 /Users/asterite-manas/.rbenv/versions/2.4.0-dev/lib/ruby/2.4.0/irb/magic-file.rb
    40 /Users/asterite-manas/.rbenv/versions/2.4.0-dev/lib/ruby/2.4.0/x86_64-darwin15/readline.bundle
    41 /Users/asterite-manas/.rbenv/versions/2.4.0-dev/lib/ruby/2.4.0/irb/input-method.rb
    42 /Users/asterite-manas/.rbenv/versions/2.4.0-dev/lib/ruby/2.4.0/irb/locale.rb
    43 /Users/asterite-manas/.rbenv/versions/2.4.0-dev/lib/ruby/2.4.0/irb.rb

[NOTE]
You may have encountered a bug in the Ruby interpreter or extension libraries.
Bug reports are welcome.
For details: http://www.ruby-lang.org/bugreport.html

Abort trap: 6

Associated revisions

Revision 75755ef1
Added by nobu (Nobuyoshi Nakada) almost 3 years ago

fix chomping newline only line

  • string.c (chomp_newline): fix chomping newline only line. rb_enc_prev_char return NULL if no previous character and must not call rb_enc_ascget on it. a patch by Ary Borenszweig at [ruby-core:78666]. [Bug #13037]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57088 b2dd03c8-39d4-4d8f-98ff-823fe69b080e

Revision 57088
Added by nobu (Nobuyoshi Nakada) almost 3 years ago

fix chomping newline only line

  • string.c (chomp_newline): fix chomping newline only line. rb_enc_prev_char return NULL if no previous character and must not call rb_enc_ascget on it. a patch by Ary Borenszweig at [ruby-core:78666]. [Bug #13037]

Revision 57088
Added by nobu (Nobuyoshi Nakada) almost 3 years ago

fix chomping newline only line

  • string.c (chomp_newline): fix chomping newline only line. rb_enc_prev_char return NULL if no previous character and must not call rb_enc_ascget on it. a patch by Ary Borenszweig at [ruby-core:78666]. [Bug #13037]

Revision 57088
Added by nobu (Nobuyoshi Nakada) almost 3 years ago

fix chomping newline only line

  • string.c (chomp_newline): fix chomping newline only line. rb_enc_prev_char return NULL if no previous character and must not call rb_enc_ascget on it. a patch by Ary Borenszweig at [ruby-core:78666]. [Bug #13037]

Revision 57088
Added by nobu (Nobuyoshi Nakada) almost 3 years ago

fix chomping newline only line

  • string.c (chomp_newline): fix chomping newline only line. rb_enc_prev_char return NULL if no previous character and must not call rb_enc_ascget on it. a patch by Ary Borenszweig at [ruby-core:78666]. [Bug #13037]

History

Updated by asterite (Ary Borenszweig) almost 3 years ago

I believe a fix for this is:

Index: string.c
===================================================================
--- string.c    (revision 57085)
+++ string.c    (working copy)
@@ -7409,8 +7409,9 @@
     if (rb_enc_is_newline(prev, e, enc)) {
    e = prev;
    prev = rb_enc_prev_char(p, e, e, enc);
-   if (rb_enc_ascget(prev, e, NULL, enc) == '\r')
+   if (prev && rb_enc_ascget(prev, e, NULL, enc) == '\r') {
        e = prev;
+   }
     }
     return e;
 }

I can verify that this works when I run make && make install, and then trying it on irb.

I tried to write a test for this, in test/ruby/test_string.rb, but doing make test doesn't seem to run it... I make changes to test_string.rb but make test doesn't seem to be running test_string.rb for some reason.

What's the correct way to add a test and try it with HEAD? Thank you!

#2

Updated by nobu (Nobuyoshi Nakada) almost 3 years ago

  • Status changed from Open to Closed

Applied in changeset r57088.


fix chomping newline only line

  • string.c (chomp_newline): fix chomping newline only line. rb_enc_prev_char return NULL if no previous character and must not call rb_enc_ascget on it. a patch by Ary Borenszweig at [ruby-core:78666]. [Bug #13037]

Also available in: Atom PDF