Project

General

Profile

Actions

Bug #11383

closed

Infinite loop in str_buf_cat triggered by str_gsub

Added by lfarcy (Laurent Farcy) almost 9 years ago. Updated almost 9 years ago.

Status:
Closed
Assignee:
-
Target version:
-
ruby -v:
ruby 2.2.2p95 (2015-04-13 revision 50295) [x86_64-linux]
[ruby-core:70074]

Description

I've got a Ruby program which reads some RSS/Atom feeds to load each of them into a relational database. It makes use of a modified version of SimpleRSS v1.2.

After moving to Ruby 2.2.2, I observe 100% CPU usage from time to time. Using gdb, I was able to identify the culprit: it's a call to str_buf_cat from str_gsub. Here's the section of code that loops in string.c (from line 2198 til line 2204).

	while (total > capa) {
	    if (capa > LONG_MAX / 2) {
		capa = (total + 4095) / 4096 * 4096;
		break;
	    }
	    capa = 2 * capa;
	}

capa is equal to 0 when the while block infinitely loops. I guess it's somehow unexpected...

Unfortunately, since the VM is looping, I cannot determine the piece of 'my' code where gsub is used. rb_eval, as found in https://github.com/michaelklishin/gdb-macros-for-ruby/blob/master/gdb_macros_for_ruby, cannot work because rb_finish cannot terminate.

But I was able to dump the backtrace and all the args and locals that lead to the infinite loop.


Files

bug-11383.log (22.8 KB) bug-11383.log nobu (Nobuyoshi Nakada), 07/22/2015 07:15 AM
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0