You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Calling hash on a Message with a repeated field will occasionally raise the following error:
RangeError: bignumtoobigtoconvertinto `long'
Test Case
I have written a gist with tests demonstrating the behavior.
Details
This is because of a bug in repeated_field.c, wherein the hash function occasionally returns a Bignum instead of a Fixnum. RepeatedField_hash can return a Bignum because of the algorithm it uses for combining hashes: bitwise shift left, then xor. If the original hash is large enough, the << will cause Ruby to automagically promote the value from a Fixnum to a Bignum.
I think the correct behavior is to use rb_hash_start -> rb_hash_uint -> rb_hash_end -> INT2FIX as storage.c does. I'd be happy to provide a patch for this if that sounds correct. I've provided a PR.
The text was updated successfully, but these errors were encountered:
Expected
All Ruby Message objects return a
hash
.Actual
Calling
hash
on a Message with a repeated field will occasionally raise the following error:Test Case
I have written a gist with tests demonstrating the behavior.
Details
This is because of a bug in
repeated_field.c
, wherein the hash function occasionally returns aBignum
instead of aFixnum
.RepeatedField_hash
can return a Bignum because of the algorithm it uses for combining hashes: bitwise shift left, then xor. If the original hash is large enough, the<<
will cause Ruby to automagically promote the value from aFixnum
to aBignum
.Ruby indicates that
hash
should return a Fixnum, so this behavior is not correct.Up the stack,
storage.c
attempts to convert this Bignum to a long, which produces theRangeError
.Proposal
I think the correct behavior is to use
rb_hash_start
->rb_hash_uint
->rb_hash_end
->INT2FIX
asstorage.c
does.I'd be happy to provide a patch for this if that sounds correct.I've provided a PR.The text was updated successfully, but these errors were encountered: