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

T

tim.j.stewart

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:in `const_get'
from d:/ruby/lib/ruby/1.8/digest.rb:18:in `const_missing'
from d:/ruby/lib/ruby/1.8/digest.rb:18:in `const_get'
from d:/ruby/lib/ruby/1.8/digest.rb:18:in `const_missing'
from d:/ruby/lib/ruby/1.8/digest.rb:18:in `const_get'
from d:/ruby/lib/ruby/1.8/digest.rb:18:in `const_missing'
from d:/ruby/lib/ruby/1.8/digest.rb:18:in `const_get'
from d:/ruby/lib/ruby/1.8/digest.rb:18:in `const_missing'
from d:/ruby/lib/ruby/1.8/digest.rb:18:in `const_get'
from d:/ruby/lib/ruby/1.8/digest.rb:18:in `const_missing'
from d:/ruby/lib/ruby/1.8/digest.rb:18:in `const_get'
from d:/ruby/lib/ruby/1.8/digest.rb:18:in `const_missing'
from d:/ruby/lib/ruby/1.8/digest.rb:18:in `const_get'
from d:/ruby/lib/ruby/1.8/digest.rb:18:in `const_missing'
from d:/ruby/lib/ruby/1.8/digest.rb:18:in `const_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:in `const_get'
from d:/ruby/lib/ruby/1.8/digest.rb:18:in `const_missing'
from d:/ruby/lib/ruby/1.8/digest.rb:18:in `const_get'
from d:/ruby/lib/ruby/1.8/digest.rb:18:in `const_missing'
from d:/ruby/lib/ruby/1.8/digest.rb:18:in `const_get'
from d:/ruby/lib/ruby/1.8/digest.rb:18:in `const_missing'
from d:/ruby/lib/ruby/1.8/digest.rb:18:in `const_get'
from d:/ruby/lib/ruby/1.8/digest.rb:18:in `const_missing'
from d:/ruby/lib/ruby/1.8/digest.rb:18:in `const_get'
from d:/ruby/lib/ruby/1.8/digest.rb:18:in `const_missing'
from d:/ruby/lib/ruby/1.8/digest.rb:18:in `const_get'
from d:/ruby/lib/ruby/1.8/digest.rb:18:in `const_missing'
from d:/ruby/lib/ruby/1.8/digest.rb:18:in `const_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
 
M

Michael Glaesemann

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 Glaesemann
grzm seespotcode net
 
D

Daniel Berger

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"

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top