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

noreply at rubyforge.org noreply at rubyforge.org
Fri Nov 12 17:46:26 EST 2010


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

Category: `gem install` command
Group: None
>Status: Closed
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
    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: Ryan Davis (zenspider)
Date: 2010-11-12 14: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 14: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 at ev2-stage ~]$ ruby -v
ruby 1.8.7 (2010-08-16 patchlevel 302) [i686-linux]
[ccook at ev2-stage ~]$ gem  -v
1.3.7
[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  ----------

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

----------------------------------------------------------------------

You can respond by visiting: 
http://rubyforge.org/tracker/?func=detail&atid=575&aid=27154&group_id=126


More information about the Rubygems-developers mailing list