Forum: Ruby "stack level too deep" when getting SHA-1 hash

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
(Guest)
on 2007-07-27 23:16
(Received via mailing list)
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
Michael G. (Guest)
on 2007-07-28 00:18
(Received via mailing list)
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
(Guest)
on 2007-07-28 01:21
(Received via mailing list)
Thank you Michael!  That works.
Daniel B. (Guest)
on 2007-07-28 01:54
(Received via mailing list)
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
This topic is locked and can not be replied to.