Bug #1883

REXML hash sometimes computes a value that is too large

Added by panesofglass (Ryan Riley) almost 3 years ago. Updated 10 months ago.

[ruby-core:24754]
Status:Open Start date:08/05/2009
Priority:Normal Due date:
Assignee:- % Done:

0%

Category:-
Target version:-
ruby -v:1.8.6p287

Description

The hash method sometimes computes a value that is too large. This is a rare occurrence in MRI, but this is causing problems for IronRuby. The following patch is suggested for computing smaller hashes:

edit: c:/ruby/libs/ruby/1.8/rexml/attribute.rb;C908357
File: attribute.rb
===================================================================
--- c:/ruby/libs/ruby/1.8/rexml/attribute.rb;C908357  (server)    6/23/2009 1:24 PM
+++ c:/ruby/libs/ruby/1.8/rexml/attribute.rb
@@ -93,7 +93,7 @@

 		# Creates (and returns) a hash from both the name and value
 		def hash
-			name.hash + value.hash
+			name.hash ^ value.hash
 		end

 		# Returns this attribute out as XML source, expanding the name
===================================================================

rexml-hash.patch - REXML hash patch (576 Bytes) panesofglass (Ryan Riley), 08/05/2009 03:24 am

History

Updated by nobu (Nobuyoshi Nakada) almost 3 years ago

Hi,

At Wed, 5 Aug 2009 03:24:49 +0900,
Ryan Riley wrote in [ruby-core:24754]:
> The hash method sometimes computes a value that is too
> large. This is a rare occurrence in MRI, but this is causing
> problems for IronRuby. The following patch is suggested for
> computing smaller hashes:

What problems?

-- 
Nobu Nakada

Updated by tmat (Tomas Matousek) almost 3 years ago

This is potential problem for MRI as well since Array#hash blows up if any item's hash is not a Fixnum:

class C
  def hash
    100000000000000000000
  end
end

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

Updated by nobu (Nobuyoshi Nakada) almost 3 years ago

Hi,

At Wed, 5 Aug 2009 04:43:31 +0900,
Tomas Matousek wrote in [ruby-core:24758]:
> This is potential problem for MRI as well since Array#hash blows up if any item's hash is not a Fixnum:

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

It's been fixed in r22308, and should be backported to 1.8.

-- 
Nobu Nakada

Updated by zenspider (Ryan Davis) about 1 year ago

I believe this patch was backported to ruby 1.8... so shouldn't this ticket be closed?

Updated by headius (Charles Nutter) 10 months ago

This does not appear to have been backported to ruby_1_8_7 branch, so we have gotten recent reports about it being a bug in JRuby. Is it possible to get this tiny patch backported to ruby_1_8_7, so we can pull the change into our patched stdlib at https://github.com/jruby/ruby/tree/jruby-ruby_1_8_7 ? I'd rather not apply the patch unilaterally, but this is a visible bug that needs fixing.

Also available in: Atom PDF