"stack level too deep" when getting SHA-1 hash


#1

Here is a session I had with irb:

[200]~% irb
irb(main):001:0> require ‘digest/sha1’
=> true
irb(main):002:0> Digest::Sha1.new.hexdigest(‘fdjslk’)
SystemStackError: stack level too deep
from d:/ruby/lib/ruby/1.8/digest.rb:9:in const_missing' from d:/ruby/lib/ruby/1.8/digest.rb:18:inconst_get’
from d:/ruby/lib/ruby/1.8/digest.rb:18:in const_missing' from d:/ruby/lib/ruby/1.8/digest.rb:18:inconst_get’
from d:/ruby/lib/ruby/1.8/digest.rb:18:in const_missing' from d:/ruby/lib/ruby/1.8/digest.rb:18:inconst_get’
from d:/ruby/lib/ruby/1.8/digest.rb:18:in const_missing' from d:/ruby/lib/ruby/1.8/digest.rb:18:inconst_get’
from d:/ruby/lib/ruby/1.8/digest.rb:18:in const_missing' from d:/ruby/lib/ruby/1.8/digest.rb:18:inconst_get’
from d:/ruby/lib/ruby/1.8/digest.rb:18:in const_missing' from d:/ruby/lib/ruby/1.8/digest.rb:18:inconst_get’
from d:/ruby/lib/ruby/1.8/digest.rb:18:in const_missing' from d:/ruby/lib/ruby/1.8/digest.rb:18:inconst_get’
from d:/ruby/lib/ruby/1.8/digest.rb:18:in const_missing' from d:/ruby/lib/ruby/1.8/digest.rb:18:inconst_get’
… 22338 levels…
from d:/ruby/lib/ruby/1.8/digest.rb:18:in const_missing' from d:/ruby/lib/ruby/1.8/digest.rb:18:inconst_get’
from d:/ruby/lib/ruby/1.8/digest.rb:18:in const_missing' from d:/ruby/lib/ruby/1.8/digest.rb:18:inconst_get’
from d:/ruby/lib/ruby/1.8/digest.rb:18:in const_missing' from d:/ruby/lib/ruby/1.8/digest.rb:18:inconst_get’
from d:/ruby/lib/ruby/1.8/digest.rb:18:in const_missing' from d:/ruby/lib/ruby/1.8/digest.rb:18:inconst_get’
from d:/ruby/lib/ruby/1.8/digest.rb:18:in const_missing' from d:/ruby/lib/ruby/1.8/digest.rb:18:inconst_get’
from d:/ruby/lib/ruby/1.8/digest.rb:18:in const_missing' from d:/ruby/lib/ruby/1.8/digest.rb:18:inconst_get’
from d:/ruby/lib/ruby/1.8/digest.rb:18:in const_missing' from d:/ruby/lib/ruby/1.8/digest.rb:18:inconst_get’
from d:/ruby/lib/ruby/1.8/digest.rb:18:in `const_missing’
from (irb):2irb(main):003:0>
irb(main):004:0* exit
[201]~% ruby -v
ruby 1.8.6 (2007-03-13 patchlevel 0) [i386-mswin32]

I tried this from two computers and got the same results. What am I
doing wrong?

Thanks!

Tim


#2

On Jul 27, 2007, at 14:15 , removed_email_address@domain.invalid wrote:

Here is a session I had with irb:

[200]~% irb
irb(main):001:0> require ‘digest/sha1’
=> true
irb(main):002:0> Digest::Sha1.new.hexdigest(‘fdjslk’)

Spelling (capitalization) and calling error? I don’t think you [need|
should use] new.

$ ruby --version
ruby 1.8.6 (2007-03-13 patchlevel 0) [powerpc-darwin8.9.0]
$ irb
irb(main):001:0> require ‘digest/sha1’
=> true
irb(main):002:0> Digest::SHA1.hexdigest(‘fdjslk’)
=> “df3d3f2922e369f348a90a5f65aef87f80e03fa7”

Michael G.
grzm seespotcode net


#3

Thank you Michael! That works.


#4

On Jul 27, 2:18 pm, Michael G. removed_email_address@domain.invalid wrote:

should use] new.

$ ruby --version
ruby 1.8.6 (2007-03-13 patchlevel 0) [powerpc-darwin8.9.0]
$ irb
irb(main):001:0> require ‘digest/sha1’
=> true
irb(main):002:0> Digest::SHA1.hexdigest(‘fdjslk’)
=> “df3d3f2922e369f348a90a5f65aef87f80e03fa7”

Yep, it’s caused by this misguided piece of code from digest.rb:

def self.const_missing(name)
case name
when :SHA256, :SHA384, :SHA512
lib = ‘digest/sha2.so’
else
lib = File.join(‘digest’, name.to_s.downcase)
end

begin
  require lib
rescue LoadError => e
  raise LoadError, "library not found for class Digest::#{name} --

#{lib}"
end

Digest.const_get(name)

end

I’d call this a bug, personally.

Regards,

Dan