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

Excluding IPs doesn't work on php7 #10373

Closed
andrzejewsky opened this issue Aug 4, 2016 · 5 comments · Fixed by #15124
Closed

Excluding IPs doesn't work on php7 #10373

andrzejewsky opened this issue Aug 4, 2016 · 5 comments · Fixed by #15124
Labels
Bug For errors / faults / flaws / inconsistencies etc.

Comments

@andrzejewsky
Copy link

Las time when we were testing Piwik with the newest version of PHP. Actually, everything looks promising except small error which arose during archivization process.

This problem is about bit-shifting in this class: https://github.com/piwik/component-network/blob/0.2.0/src/IPUtils.php.
Look at line https://github.com/piwik/component-network/blob/0.2.0/src/IPUtils.php#L182
Sometimes variable $n is a negative number and in the PHP7 it will throw an exception because this version of PHP introduced exceptions instead of fatal errors, null values etc.

small example:

// php 5.6
var_dump(1 << 1); // int(2)
var_dump(1 << -1); // int(-9223372036854775808)
var_dump(-1 << 1); // int(-2)
var_dump(~((1 << $n) - 1)); // int(9223372036854775807) when $n = -1

// php 7
var_dump(1 << 1); // int(2)
var_dump(1 << -1); // Uncaught ArithmeticError: Bit shift by negative number
var_dump(-1 << 1); // int(-2)
var_dump(~((1 << $n) - 1)); // Uncaught ArithmeticError: Bit shift by negative number  when $n = -1

@mattab
Copy link
Member

mattab commented Aug 4, 2016

Thanks @andrzejewsky for the bug report! If you can help, consider submitting a unit test reproducing the bug on PHP7 👍

@mattab mattab added this to the 2.16.x (LTS) milestone Aug 16, 2016
@mattab mattab added the Bug For errors / faults / flaws / inconsistencies etc. label Aug 16, 2016
@mattab mattab modified the milestones: 2.16.x (LTS), 3.0.0 Aug 25, 2016
robocoder added a commit to robocoder/component-network that referenced this issue Mar 29, 2018
@robocoder
Copy link
Contributor

Tracked down this bug to an invalid range (i.e., missing the suffix).

See PR for fix and updated test.

@mattab
Copy link
Member

mattab commented Jul 1, 2019

Hi @andrzejewsky
Could you maybe test the following pr and confirm if it fixes the issue for you? https://github.com/matomo-org/component-network/pull/10/files

@alex-whitney
Copy link

@mattab - I have tested that change and it appears to resolve this issue for me.

@tsteur
Copy link
Member

tsteur commented Nov 6, 2019

thanks @alex-whitney created #15124

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug For errors / faults / flaws / inconsistencies etc.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants