@andrzejewsky opened this Issue on August 4th 2016 Contributor

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 commented on August 4th 2016 Member

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

@robocoder commented on March 29th 2018 Contributor

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

See PR for fix and updated test.

@mattab commented on July 1st 2019 Member

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

Powered by GitHub Issue Mirror