iconara / cql-rb

Cassandra CQL 3 binary protocol driver for Ruby
106 stars 31 forks source link

Taking the hash of an array containing a Uuid can overflow JRuby long #81

Closed outoftime closed 10 years ago

outoftime commented 10 years ago

To reproduce:

['mycat', Cql::Uuid.new(162917432198567078063626261009205865234)].hash

Backtrace:

RangeError: bignum too big to convert into `long'
        from org/jruby/RubyArray.java:689:in `hash'
        from (irb):1:in `evaluate'

I notice that the #hash returned by a Uuid is roughly 64 bits, whereas that of, say, a String is roughly 32 bits in jruby. (In MRI, String also returns a 64-bit hash).

So it seems like the Uuid#hash implementation should return an integer of no more than 32 bits on jruby, although I'm guessing there's a better thing to check than “is this jruby”. Thoughts? I'd be happy to dig deeper if nothing comes to mind.

iconara commented 10 years ago

Ah, I've made a silly mistake in Uuid#hash. I use the mask 0xffffffffffffffff so what comes out is an unsigned long and will overflow a Java long. A 32 bit hash value would probably work just as well.

Thanks for the bug report, I will try to fix this and push out a v1.2.1 soon.

iconara commented 10 years ago

v1.2.1 is out.

outoftime commented 10 years ago

@iconara thanks!!