Project

General

Profile

Actions

Bug #4050

closed

segfault while using regex in an infinite loop

Added by mattoufoutu (Mathieu D) over 13 years ago. Updated almost 13 years ago.

Status:
Rejected
Assignee:
-
Target version:
ruby -v:
ruby 1.9.2p0 (2010-08-18 revision 29036) [i686-linux]
Backport:
[ruby-core:33158]

Description

=begin
While learning ruby, I noticed that Regex matches were kept in memory to be able to access groups elements
with $1, $2, and so on later in the code.
So I wondered if this could fill my memory, and tried the following code:

 s = "a"
 while true do
     s = s*2
     s[/a+/]
 end

Which lead to a segmentation fault.
(here is the full backtrace from irb: http://www.ideone.com/kNioo )

I first thought that it was because my "s" variable was getting bigger and bigger, but after a simple
test I noticed that it threw an ArgumentError.
Shouldn't this throw an exception too? so it could be caught in the code.

If I missed something (as said, i'm really new to ruby) and this report is pointless, I'm sorry,
otherwise I hope it will be useful.

Best regards.

Mat
=end

Actions #1

Updated by naruse (Yui NARUSE) over 13 years ago

=begin
Usually ruby runs GC on low memory.
But this program hold a huge memory by variable s, so it will crash.
=end

Actions #2

Updated by naruse (Yui NARUSE) over 13 years ago

  • Status changed from Open to Rejected

=begin

=end

Actions

Also available in: Atom PDF

Like0
Like0Like0