[Rubygems-developers] [ rubygems-Bugs-27154 ] Computed hash is sometimes too large.

noreply at rubyforge.org noreply at rubyforge.org
Mon Oct 18 17:08:06 EDT 2010

Bugs item #27154, was opened at 2009-09-21 14:42
You can respond by visiting: 

Category: `gem install` command
Group: None
Status: Open
Resolution: None
Priority: 3
Submitted By: Ryan Riley (panesofglass)
Assigned to: Nobody (None)
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

[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 @@
   def hash # :nodoc:
-    name.hash + type.hash + version_requirements.hash
+    name.hash ^ type.hash ^ version_requirements.hash
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


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


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 ::] Installing mysql (2.8.1)
 ** [out ::] with native extensions
 ** [out ::] /usr/lib/ruby/site_ruby/1.8/rubygems/requirement.rb:109:in `hash'
 ** [out ::] :
 ** [out ::] bignum too big to convert into `long'
 ** [out ::] (
 ** [out ::] RangeError
 ** [out ::] )
 ** [out ::] from /usr/lib/ruby/site_ruby/1.8/rubygems/requirement.rb:109:in `hash'
 ** [out ::] from /usr/lib/ruby/site_ruby/1.8/rubygems/specification.rb:675:in `hash'
 ** [out ::] from /usr/lib/ruby/1.8/fileutils.rb:243:in `inject'
 ** [out ::] from /usr/lib/ruby/site_ruby/1.8/rubygems/specification.rb:674:in `each'
 ** [out ::] from /usr/lib/ruby/site_ruby/1.8/rubygems/specification.rb:674:in `inject'
 ** [out ::] from /usr/lib/ruby/site_ruby/1.8/rubygems/specification.rb:674:in `hash'
 ** [out ::] from /usr/lib/ruby/1.8/tsort.rb:205:in `include?'
 ** [out ::] from /usr/lib/ruby/1.8/tsort.rb:205:in `each_strongly_connected_component_from'
 ** [out ::] ... 22 levels...
 ** [out ::] from /usr/lib/ruby/gems/1.8/gems/bundler-1.0.2/lib/bundler/vendor/thor/base.rb:389:in `start'
 ** [out ::] from /usr/lib/ruby/gems/1.8/gems/bundler-1.0.2/bin/bundle:13
 ** [out ::] from /usr/bin/bundle:19:in `load'
 ** [out ::] from /usr/bin/bundle:19
----------- end cap output -------------------

------------ system & ruby info ------------------
[ccook at ev2-stage ~]$ ruby -v
ruby 1.8.7 (2010-08-16 patchlevel 302) [i686-linux]
[ccook at ev2-stage ~]$ gem  -v
[ccook at 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  ----------


----------- 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!



You can respond by visiting: 

More information about the Rubygems-developers mailing list