Comments (15)
Hi guys.
Firstly, I'd like to apologise for commenting on a closed issue.
I encountered the same problem reported by @ChristianVermeulen et al.
I'm running LIIP OSX packages 7.0.8 and 7.1.0 on OSX El Capitan. These packages include both GMP and BCMath.
The number I tried to encode was very large - over 1 billion - but still much lower than PHP_INT_MAX
as displayed on my system.
I dug into it a little and found that gmp_div
is the culprit. It immediately segfaults, irrespective of the size of the values passed into it. The other gmp
functions operate without error.
I temporarily adjusted the source of \Hashids\Hashids::__construct()
to prefer the BCMath functions instead and found that they work fine.
Same goes for the stock El Capitan PHP 5.5, which only has BCMath installed.
This is clearly environmental and is nothing to do with the Hashids codebase itself, but I thought I'd report on the above findings in case it's useful to anyone else googling this issue in future.
from hashids.
Apologies for responding to a closed issue, but for anyone else running El-Capitan / OSX with liip PHP, I can confirm that the problem is with gmp_div_q which seg faults and this is why encode() fails for this package. As work around, adjust the divide function in src/Math.php and remove the call to gmp_div_q
public static function divide($a, $b)
{
/*
if (function_exists('gmp_div_q')) {
return gmp_div_q($a, $b);
}*/
return bcdiv($a, $b, 0);
}
from hashids.
I'd just like to chime in as I'm experiencing the same issue running 1.0.6 on a Homestead VM. Numbers more than 10 digits result in Hashids::encode()
returning an empty string, whereas numbers less than 10 digits produce expected encoding results.
Per the OP's mention of Macs though, what's really strange is the problem only arises when running Hashids::encode()
on an app hosted on Homestead; if I use my local OS X-hosted Psy shell PHP interactive environment to run the same Hashids::encode() command with a 10+ digit number, it produces the expected result.
from hashids.
Duh maybe if I'd read the README the issue would be obvious. If anybody else is having this issue read the README section "Big Numbers".
from hashids.
So, i checked the big number section... I have Bcmath installed and verified the upper limit is increased with $hashids->get_max_int_value()
which returns 9223372036854775807
.
I'm using a timestamp as int to generate the hash (no need for decoding, I just need a userfriendly unique string for copying over by hand). The timestamp has 10 digits. When I use anything below 10 digits it works fine, but as soon as I hit 10 or more it crashes and I get the blank screen as well.
- OSX El Capitan
- PHP 7.0.4 (phposx-liip)
- Apache 2.4.18
- Symfony 3
from hashids.
So, if you're having issues with big numbers, please check your setup. Also, from README
:
It will then use regular arithmetic on numbers less than 1 billion (because it's faster), and one of these libraries if greater than. GMP takes precedence over BCMath.
10 digits and up: the library is using either GMP or BCMath. Those functions are gmp_add
, gmp_div
, gmp_strval
and bcadd
, bcdiv
, strval
. Try simple arithmetic with those functions manually to verify they're working for you.
This PHP library has been tested with big numbers, and they worked as expected before; so unless something changed in PHP or those libraries, the issue is probably in your setup.
Closing for now, please re-open if you find something in code.
from hashids.
I just checked if those functions are available and seem to be:
echo function_exists ( 'gmp_add' );
echo '<br/>';
echo function_exists ( 'gmp_div' );
echo '<br/>';
echo function_exists ( 'gmp_strval' );
echo '<br/>';
echo function_exists ( 'bcadd' );
echo '<br/>';
echo function_exists ( 'bcdiv' );
echo '<br/>';
echo function_exists ( 'strval' );
outputs:
1
1
1
1
1
1
If you have any others tests you would like me to run, let me know.
But for now it seems the issue is definitely not resolved :(
from hashids.
but as soon as I hit 10 or more it crashes and I get the blank screen as well
What's the error you're getting in the error log?
from hashids.
There is nothing interesting in logs:
AH00052: child pid 49418 exit signal Segmentation fault (11)
No matter which OS version, PHP version or apache version. Maybe a bug in mathlibs.
To anyone who wants to use this class on Mac use the fix from the first message.
from hashids.
Okay, so far I'm unable to reproduce, but will have to investigate.
from hashids.
@oleghind are you still having issues with this?
from hashids.
Closing this since we can't reproduce it. If anyone are still having issues with this please open a new issue and we'll take a look at it!
from hashids.
@darraghenright thanks for the info, useful 👍
from hashids.
I can confirm I'm also having this issue on mac. Would it be possible to get a fix integrated?
from hashids.
I can also confirm having this issue on mac. Thank god @moopa responded to a closed issue!!
In my case there was a segmentation fall when invoking:
gmp_div_q(3, 44);
Clearly an environment problem using gmp.php
in Mac but still don't know how to fix it.
from hashids.
Related Issues (20)
- Padding/minimum value not being respected HOT 1
- Laravel 9 has been released. Would be awesome if we could add support to this package 🚀 HOT 1
- Ability to encode fractions/decimal places HOT 2
- TypeError: Unsupported operand types: int - string on PHP 8.1 HOT 1
- [PHP 8.1] Deprecated: Implicit conversion from float-string to int loses precision HOT 1
- 2 particulars numbers render the exact same result whatever the salt used ???!!! HOT 1
- Is there any max length for the salt? HOT 2
- How can I get more randomness? HOT 1
- Implicit conversion from float-string HOT 1
- How to use without Composer? HOT 6
- Parsing ERROR? HOT 2
- Error Invalid text representation (hashids not decoding) with route in plural HOT 1
- Different results for large numbers between 32-bit and 64-bit HOT 1
- encode number 1 but got different values in laravel and hyperf project HOT 2
- xdffx dsdxsazazjjk
- Missing math extension for Hashids, install either bcmath or gmp. HOT 6
- HashIds not working with macOS Sonoma 14.2 HOT 3
- Github Actions produces gmp_mod(): Argument #1 ($num1) must be of type GMP|string|int error HOT 1
- gmp_mod Argument #1 ($num1) is not an integer string HOT 3
- Same result for different numbers HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from hashids.