Skip to content
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

Closed
tobsn opened this issue Jan 25, 2013 · 6 comments
Closed

Unhandled Exception on Windows 7 64bit #3

tobsn opened this issue Jan 25, 2013 · 6 comments

Comments

@tobsn
Copy link

tobsn commented Jan 25, 2013

Unhandled Exception
Message: Uninitialized string offset: -12
Location: Hashids\Hashids.php on line 111

Code that errors out:
encrypt( 339585589, 2147483647 );

@jd327
Copy link
Collaborator

jd327 commented Jan 25, 2013

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.

@tobsn
Copy link
Author

tobsn commented Jan 29, 2013

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.

@jd327
Copy link
Collaborator

jd327 commented Jan 29, 2013

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?

@miquelfire
Copy link

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.

@jd327
Copy link
Collaborator

jd327 commented Jan 30, 2013

Yep thanks, looking into it as well.

@jd327
Copy link
Collaborator

jd327 commented Feb 1, 2013

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.

@jd327 jd327 closed this as completed Feb 4, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants