Project

General

Profile

Bug #7870

Time.now == "" causes an infinite loop

Added by drbrain (Eric Hodel) over 4 years ago. Updated over 4 years ago.

Status:
Closed
Priority:
Normal
Target version:
ruby -v:
ruby 2.0.0dev (2013-02-08) [x86_64-darwin12.2.1]
[ruby-core:52305]

Description

=begin
This is a regression from 1.9.

2.0.0 branch:

$ ./ruby20 -v ../branches/ruby_2_0_0/test.rb
ruby 2.0.0dev (2013-02-08) [x86_64-darwin12.2.1]
../branches/ruby_2_0_0/test.rb:1: warning: possibly useless use of == in void context
../branches/ruby_2_0_0/test.rb:1: stack level too deep (SystemStackError)

1.9:

$ ruby19 -v test.rb
ruby 1.9.3p374 (2013-01-15 revision 38858) [x86_64-darwin12.2.1]
test.rb:1: warning: possibly useless use of == in void context

This also reproduces in trunk.

=end

Associated revisions

Revision 39292
Added by nobu (Nobuyoshi Nakada) over 4 years ago

compar.c: inversed comarison without infinite recursion

  • compar.c (rb_invcmp): compare by inversed comarison, with preventing from infinite recursion. [Bug #7870]
  • string.c (rb_str_cmp_m), time.c (time_cmp): get rid of infinite recursion.

Revision 39292
Added by nobu (Nobuyoshi Nakada) over 4 years ago

compar.c: inversed comarison without infinite recursion

  • compar.c (rb_invcmp): compare by inversed comarison, with preventing from infinite recursion. [Bug #7870]
  • string.c (rb_str_cmp_m), time.c (time_cmp): get rid of infinite recursion.

Revision 39292
Added by nobu (Nobuyoshi Nakada) over 4 years ago

compar.c: inversed comarison without infinite recursion

  • compar.c (rb_invcmp): compare by inversed comarison, with preventing from infinite recursion. [Bug #7870]
  • string.c (rb_str_cmp_m), time.c (time_cmp): get rid of infinite recursion.

Revision 39292
Added by nobu (Nobuyoshi Nakada) over 4 years ago

compar.c: inversed comarison without infinite recursion

  • compar.c (rb_invcmp): compare by inversed comarison, with preventing from infinite recursion. [Bug #7870]
  • string.c (rb_str_cmp_m), time.c (time_cmp): get rid of infinite recursion.

History

#1 [ruby-core:52306] Updated by drbrain (Eric Hodel) over 4 years ago

  • Assignee set to nobu (Nobuyoshi Nakada)

r38044 is the culprit.

Previously Ruby would return nil if the other object did not have to_str, now ruby calls other <=> self when other is not a String and does not have <=> leading to the infinite loop.

#2 [ruby-core:52351] Updated by mame (Yusuke Endoh) over 4 years ago

  • Priority changed from 6 to Normal

I don't think that this is a showstopper, unless there is many or famous application depending on this behavior. Do you know anything?

After it is fixed in trunk, we may backport the patch to 2.0.0, but don't necessarily have to do so. I guess that it can be fixed 2.0.0-pXXX later (depending on Nagachika-san).

--
Yusuke Endoh mame@tsg.ne.jp

#3 [ruby-core:52364] Updated by drbrain (Eric Hodel) over 4 years ago

Fog breaks due to this change (it is how I discovered it):

https://github.com/fog/fog/blob/master/lib/fog/core/attributes.rb#L53-L62

This compares a Time with the empty string leading to the infinite loop.

Fog provides an API for cloud services such as Amazon AWS, OpenStack, etc. It is fairly popular.

#4 [ruby-core:52366] Updated by ko1 (Koichi Sasada) over 4 years ago

  • Priority changed from Normal to 6

#5 [ruby-core:52373] Updated by mame (Yusuke Endoh) over 4 years ago

  • Status changed from Open to Assigned

drbrain, thank you! That is terrible.

Nobu, please check and fix it!

--
Yusuke Endoh mame@tsg.ne.jp

#6 Updated by nobu (Nobuyoshi Nakada) over 4 years ago

  • Status changed from Assigned to Closed
  • % Done changed from 0 to 100

This issue was solved with changeset r39292.
Eric, thank you for reporting this issue.
Your contribution to Ruby is greatly appreciated.
May Ruby be with you.


compar.c: inversed comarison without infinite recursion

  • compar.c (rb_invcmp): compare by inversed comarison, with preventing from infinite recursion. [Bug #7870]
  • string.c (rb_str_cmp_m), time.c (time_cmp): get rid of infinite recursion.

Also available in: Atom PDF