-
Notifications
You must be signed in to change notification settings - Fork 415
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unhandled Exception on Windows 7 64bit #3
Comments
Ah thanks, good catch, will take a look at this tonight. Edit: Yep, it looks like a max integer value overflow that's causing unexpected behavior. Will have to clean it up in a few places & recheck for collisions on a bigger scale. Hang tight. |
any updates on it? my buddy here goes crazy because every second request he gets that exception ;) edit: we also checked, he has a 32bit php install. so it definitely is the int limit. |
Hi Tobias, I am working on it -- it actually takes longer to test it (for speed and collisions), then to code it :( The main problem is the arithmetic because to balance speed and randomness I have to do math on integer parameters (so even if individual integers are not greater than PHP_INT_MAX, addition on them might be). And when PHP does math on big numbers, it starts approximating with floats -- which is usually not a problem, but kind of a problem when encrypting + decrypting :) So anyway, I have to use PHP's BC Math library for big numbers - unfortunately it's a bit slower than regular arithmetic. And I have to balance speed and accuracy. Edit: Can I ask what he's encrypting that he needs such big numbers? |
If possible, see about using GMP if it's there, then fall back to BC Math. GMP can be MUCH faster than BC Math. Also, if the numbers will fit, GMP will use normal math like you normally would use if you don't have to worry about PHP_INT_MAX. I wish I remembered that library that allowed three different libraries (the third was a pure PHP class maybe?) to be used, but it had a wrapper so it didn't matter which of the three was used as it made a single API for it. Might be Crypt_RSA in PEAR. |
Yep thanks, looking into it as well. |
Just pushed v0.3.0, also updated README. @tobsn not sure what you (or your friend) are doing with such big numbers on 32-bit system, but you could try to split them up since hashids supports multiple number encoding. @miquelfire thanks for the GMP tip, now trying to use that + BCMath. Not closing this issue yet because still testing. |
Unhandled Exception
Message: Uninitialized string offset: -12
Location: Hashids\Hashids.php on line 111
Code that errors out:
encrypt( 339585589, 2147483647 );
The text was updated successfully, but these errors were encountered: