Giter VIP home page Giter VIP logo

Comments (15)

darraghenright avatar darraghenright commented on August 19, 2024 2

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.

moopa avatar moopa commented on August 19, 2024 1

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.

wjgilmore avatar wjgilmore commented on August 19, 2024

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.

wjgilmore avatar wjgilmore commented on August 19, 2024

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.

ChristianVermeulen avatar ChristianVermeulen commented on August 19, 2024

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

screenshot 2016-05-03 13 13 47

from hashids.

jd327 avatar jd327 commented on August 19, 2024

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.

ChristianVermeulen avatar ChristianVermeulen commented on August 19, 2024

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.

jd327 avatar jd327 commented on August 19, 2024

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.

oleghind avatar oleghind commented on August 19, 2024

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.

jd327 avatar jd327 commented on August 19, 2024

Okay, so far I'm unable to reproduce, but will have to investigate.

from hashids.

vinkla avatar vinkla commented on August 19, 2024

@oleghind are you still having issues with this?

from hashids.

vinkla avatar vinkla commented on August 19, 2024

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.

jd327 avatar jd327 commented on August 19, 2024

@darraghenright thanks for the info, useful 👍

from hashids.

deanc avatar deanc commented on August 19, 2024

I can confirm I'm also having this issue on mac. Would it be possible to get a fix integrated?

from hashids.

guilleferrer avatar guilleferrer commented on August 19, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.