Computed hash is sometimes too large

Took long enough, but it would appear the fix to #hash has finally made
it
into rubygems.

Ryan R.

Email: [email protected]
LinkedIn: http://www.linkedin.com/in/ryanriley
Blog: http://wizardsofsmart.net/
Website: http://panesofglass.org/

---------- Forwarded message ----------
From: [email protected]
Date: Tue, Mar 1, 2011 at 10:54 AM
Subject: [ rubygems-Bugs-27154 ] Computed hash is sometimes too large.
To: [email protected]

Bugs item #27154, was opened at 2009-09-21 16:42
You can respond by visiting:
http://rubyforge.org/tracker/?func=detail&atid=575&aid=27154&group_id=126

Category: gem install command
Group: v1.3.x
Status: Closed
Resolution: Accepted
Priority: 3
Submitted By: Ryan R. (panesofglass)
Assigned to: John B. (jbarnette)
Summary: Computed hash is sometimes too large.

Initial Comment:
The current hash algorithm in dependency.rb (line 138) and
specification.rb
(line 658) can sometimes create a hash that is too large. This is also
possible with Array#hash in MRI, which can also misbehave if one of the
array elements returns a large hash value:

class C
def hash
100000000000000000000
end
end

[C.new].hash # => in hash': bignum too big to convert into long’ (RangeError)

REXML has a similar issue. http://redmine.ruby-
lang.org/issues/show/1883 tracks the issue, and MRI will be
fixing the issue.

Suggested fixes are:

edit: c:/ruby/libs/ruby/site_ruby/1.8/rubygems/dependency.rb;C840659
File: dependency.rb

— c:/ruby/libs/ruby/site_ruby/1.8/rubygems/dependency.rb;C840659
(server)
6/23/2009 1:21 PM
+++ c:/ruby/libs/ruby/site_ruby/1.8/rubygems/dependency.rb
@@ -112,7 +112,7 @@
end

def hash # :nodoc:

  • name.hash + type.hash + version_requirements.hash
  • name.hash ^ type.hash ^ version_requirements.hash
    end

end

edit: c:/ruby/libs/ruby/site_ruby/1.8/rubygems/specification.rb;C908357
File: specification.rb

— c:/ruby/libs/ruby/site_ruby/1.8/rubygems/specification.rb;C908357
(server) 6/23/2009 1:24 PM
+++ c:/ruby/libs/ruby/site_ruby/1.8/rubygems/specification.rb
@@ -661,9 +661,8 @@
private :same_attributes?

def hash # :nodoc:
  •  @@attributes.inject(0) { |hash_code, (name, default_value)|
    
  •    n = self.send(name).hash
    
  •    hash_code + n
    
  •  @@attributes.inject(612553) { |hash_code, (name, default_value)|
    
  •    hash_code ^ self.send(name).hash
    }
    
    end

===================================================================


Comment By: Bernard L. (blambeau)
Date: 2011-03-01 19:54

Message:
This bug seems to re-appear. requirement.rb should probably be patched
as
proposed by Daniel Weaver to guarantee compatibility with ruby
1.8.7-p176.

I’ve written a review with additional details about this bug at:


Comment By: Eric H. (drbrain)
Date: 2011-02-02 01:03

Message:
This is fixed.


Comment By: Daniel Weaver (zlern2k)
Date: 2010-12-20 21:20

Message:
I realize these are bugs in the underlying Ruby implementation of hash,
but
it really helps us to have them fixed in gem.

This is the patch for requirement.rb that we currently need to deploy to
make bundler happy with our apps:

zlerntop:rubygems danielweaver$ diff -u requirement.rb.orig
requirement.rb
— requirement.rb.orig 2010-12-20 12:13:40.000000000 -0800
+++ requirement.rb 2010-12-20 12:13:40.000000000 -0800
@@ -106,7 +106,7 @@
end

def hash # :nodoc:

  • requirements.hash
  • requirements.inject(0) { |h, r| h ^ r.first.hash ^ r.last.hash }
    end

def marshal_dump # :nodoc:


Comment By: George M. (gsmendoza)
Date: 2010-12-07 05:06

Message:
Hello again,

I got the bignum error again, but this time with cucumber-0.9.4. These
commands weren’t able to install the gem:

  • bundle install
  • bundle install --local
  • sudo bundle install --local
  • sudo bundle install --local --system
  • sudo bundle install --system

However, I was able to work around the issue by

  1. installing the gem to my system manually (sudo gem install cucumber
    –version “0.9.4”), and
  2. installing the bundle to the system (sudo bundle install --system)

For step 2, trying “bundle install --local” worked only if all the gems
in
the bundle are already installed. If there were some gems from the
bundle
that are not installed, running “sudo bundle install --system” was the
only
way I could install them.

George M.
Philippines


Comment By: George M. (gsmendoza)
Date: 2010-12-01 04:52

Message:
Hello,

Appreciate if anybody can re-open this ticket. I am also getting the
error
when I try to install the dmitryv-backup gem via bundle. Please let me
know
if I need to provide any other information in order to fix this bug.
Thanks!

Gemfile:

source :rubygems
source “http://gems.github.com

#…

gem ‘dmitryv-backup’, ‘2.4.0’, :require => “backup”

#…


Running:

bundle install --local
/usr/local/lib/site_ruby/1.8/rubygems/requirement.rb:109:in hash': bignum too big to convert into long’ (RangeError)
from /usr/local/lib/site_ruby/1.8/rubygems/requirement.rb:109:in hash' from /usr/local/lib/site_ruby/1.8/rubygems/specification.rb:675:in hash’
from
/usr/lib/ruby/gems/1.8/gems/bundler-1.0.7/lib/bundler/index.rb:36:in
inject' from /usr/local/lib/site_ruby/1.8/rubygems/specification.rb:674:in each’
from /usr/local/lib/site_ruby/1.8/rubygems/specification.rb:674:in
inject' from /usr/local/lib/site_ruby/1.8/rubygems/specification.rb:674:in hash’
from /usr/lib/ruby/1.8/tsort.rb:204:in include?' from /usr/lib/ruby/1.8/tsort.rb:204:in each_strongly_connected_component_from’
from
/usr/lib/ruby/gems/1.8/gems/bundler-1.0.7/lib/bundler/spec_set.rb:130:in
tsort_each_child' from /usr/lib/ruby/gems/1.8/gems/bundler-1.0.7/lib/bundler/spec_set.rb:130:in each’
from
/usr/lib/ruby/gems/1.8/gems/bundler-1.0.7/lib/bundler/spec_set.rb:130:in
tsort_each_child' from /usr/lib/ruby/gems/1.8/gems/bundler-1.0.7/lib/bundler/spec_set.rb:128:in each’
from
/usr/lib/ruby/gems/1.8/gems/bundler-1.0.7/lib/bundler/spec_set.rb:128:in
tsort_each_child' from /usr/lib/ruby/1.8/tsort.rb:203:in each_strongly_connected_component_from’
from /usr/lib/ruby/1.8/tsort.rb:209:in
each_strongly_connected_component_from' from /usr/lib/ruby/gems/1.8/gems/bundler-1.0.7/lib/bundler/spec_set.rb:130:in tsort_each_child’
from
/usr/lib/ruby/gems/1.8/gems/bundler-1.0.7/lib/bundler/spec_set.rb:130:in
each' from /usr/lib/ruby/gems/1.8/gems/bundler-1.0.7/lib/bundler/spec_set.rb:130:in tsort_each_child’
from
/usr/lib/ruby/gems/1.8/gems/bundler-1.0.7/lib/bundler/spec_set.rb:128:in
each' from /usr/lib/ruby/gems/1.8/gems/bundler-1.0.7/lib/bundler/spec_set.rb:128:in tsort_each_child’
from /usr/lib/ruby/1.8/tsort.rb:203:in
each_strongly_connected_component_from' from /usr/lib/ruby/1.8/tsort.rb:182:in each_strongly_connected_component’
from
/usr/lib/ruby/gems/1.8/gems/bundler-1.0.7/lib/bundler/spec_set.rb:124:in
tsort_each_node' from /usr/lib/ruby/gems/1.8/gems/bundler-1.0.7/lib/bundler/spec_set.rb:124:in each’
from
/usr/lib/ruby/gems/1.8/gems/bundler-1.0.7/lib/bundler/spec_set.rb:124:in
tsort_each_node' from /usr/lib/ruby/1.8/tsort.rb:180:in each_strongly_connected_component’
from /usr/lib/ruby/1.8/tsort.rb:148:in tsort_each' from /usr/lib/ruby/1.8/tsort.rb:135:in tsort’
from
/usr/lib/ruby/gems/1.8/gems/bundler-1.0.7/lib/bundler/spec_set.rb:107:in
sorted' from /usr/lib/ruby/gems/1.8/gems/bundler-1.0.7/lib/bundler/spec_set.rb:12:in each’
from
/usr/lib/ruby/gems/1.8/gems/bundler-1.0.7/lib/bundler/installer.rb:44:in
run' from /usr/lib/ruby/gems/1.8/gems/bundler-1.0.7/lib/bundler/installer.rb:8:in install’
from
/usr/lib/ruby/gems/1.8/gems/bundler-1.0.7/lib/bundler/cli.rb:225:in
install' from /usr/lib/ruby/gems/1.8/gems/bundler-1.0.7/lib/bundler/vendor/thor/task.rb:22:in send’
from
/usr/lib/ruby/gems/1.8/gems/bundler-1.0.7/lib/bundler/vendor/thor/task.rb:22:in
run' from /usr/lib/ruby/gems/1.8/gems/bundler-1.0.7/lib/bundler/vendor/thor/invocation.rb:118:in invoke_task’
from
/usr/lib/ruby/gems/1.8/gems/bundler-1.0.7/lib/bundler/vendor/thor.rb:246:in
dispatch' from /usr/lib/ruby/gems/1.8/gems/bundler-1.0.7/lib/bundler/vendor/thor/base.rb:389:in start’
from /usr/lib/ruby/gems/1.8/gems/bundler-1.0.7/bin/bundle:13
from /usr/bin/bundle:19:in `load’
from /usr/bin/bundle:19

Thanks,

George M.
Philippines


Comment By: Ryan D. (zenspider)
Date: 2010-11-12 23:46

Message:
This ticket has been deemed stale and we’re closing it in order to catch
up
with our ticket list. If you think it is still valid, please reopen.


Comment By: Craig Cook (ccook)
Date: 2010-10-18 23:08

Message:
Hello,

I tried this patch, but I am still getting the error, at the same place
in
the code. The error is the same with or without the patch to
specification.rb; dependency.rb was already like the patched part shown
above. This happened when installing using bundler, executed via
capistrano.

We had been using hpricot, it wasn’t needed, it was giving this error
first. I took it out, but then the same RangeError happened with
mysql.
I’ve seen it before also with nokogiri. (Always with native gems,
though).

Here’s the relevant part of the log:
----------- begin log ----------------------------
** [out :: 192.168.10.63] Installing mysql (2.8.1)
** [out :: 192.168.10.63] with native extensions
** [out :: 192.168.10.62]
/usr/lib/ruby/site_ruby/1.8/rubygems/requirement.rb:109:in hash' ** [out :: 192.168.10.62] : ** [out :: 192.168.10.62] bignum too big to convert into long’
** [out :: 192.168.10.62] (
** [out :: 192.168.10.62] RangeError
** [out :: 192.168.10.62] )
** [out :: 192.168.10.62] from
/usr/lib/ruby/site_ruby/1.8/rubygems/requirement.rb:109:in hash' ** [out :: 192.168.10.62] from /usr/lib/ruby/site_ruby/1.8/rubygems/specification.rb:675:in hash’
** [out :: 192.168.10.62] from /usr/lib/ruby/1.8/fileutils.rb:243:in
inject' ** [out :: 192.168.10.62] from /usr/lib/ruby/site_ruby/1.8/rubygems/specification.rb:674:in each’
** [out :: 192.168.10.62] from
/usr/lib/ruby/site_ruby/1.8/rubygems/specification.rb:674:in inject' ** [out :: 192.168.10.62] from /usr/lib/ruby/site_ruby/1.8/rubygems/specification.rb:674:in hash’
** [out :: 192.168.10.62] from /usr/lib/ruby/1.8/tsort.rb:205:in
include?' ** [out :: 192.168.10.62] from /usr/lib/ruby/1.8/tsort.rb:205:in each_strongly_connected_component_from’
** [out :: 192.168.10.62] … 22 levels…
** [out :: 192.168.10.62] from
/usr/lib/ruby/gems/1.8/gems/bundler-1.0.2/lib/bundler/vendor/thor/base.rb:389:in
start' ** [out :: 192.168.10.62] from /usr/lib/ruby/gems/1.8/gems/bundler-1.0.2/bin/bundle:13 ** [out :: 192.168.10.62] from /usr/bin/bundle:19:in load’
** [out :: 192.168.10.62] from /usr/bin/bundle:19
----------- end cap output -------------------

running:
------------ system & ruby info ------------------
[ccook@ev2-stage ~]$ ruby -v
ruby 1.8.7 (2010-08-16 patchlevel 302) [i686-linux]
[ccook@ev2-stage ~]$ gem -v
1.3.7
[ccook@ev2-stage ~]$ uname -a
Linux ev2-stage 2.6.18-194.11.4.el5xen #1 SMP Tue Sep 21 06:28:04 EDT
2010
i686 i686 i386 GNU/Linux
------ end system / ruby info ----------

Gemfile:

----------- begin Gemfile -----------------
source :gemcutter

gem ‘rails’, ‘2.3.8’
gem ‘mysql’, ‘2.8.1’
gem “geokit”
gem “geokit-rails”
gem “builder”
gem ‘chronic’
gem ‘whenever’
gem ‘database_cleaner’
gem ‘apn_on_rails’
gem ‘factory_girl’
gem ‘net-sftp’
gem ‘will_paginate’ # dependency for squirrel & jqgrid
gem ‘nokogiri’ # only for
test/functional/auth_controller_test.rb

gem ‘cucumber’
gem ‘cucumber-rails’
gem ‘webrat’
gem ‘rspec’

---------- end Gemfile -----------------

So, is this the same issue? It sure looks like it to me. I hope not to
have
to dive into the innards of rubygems if possible. But we need to be
able
to deploy. The app is working and passing tests on development, but
hard to
say on staging as we can’t get it over there with cap. I suppose it
could
all be done by hand once anyway, but we (other dev on my team and I )
need
to be able to do this over again.

Thanks for your time in this!

Cheers,
Craig