Skip to content

Fix running on x86#26

Closed
nicolas-grekas wants to merge 1 commit intoDaveRandom:2.xfrom
nicolas-grekas:x86
Closed

Fix running on x86#26
nicolas-grekas wants to merge 1 commit intoDaveRandom:2.xfrom
nicolas-grekas:x86

Conversation

@nicolas-grekas
Copy link

@nicolas-grekas nicolas-grekas commented Feb 28, 2022

const FLAG_NO_COMPRESSION = 0x80000000; is a float on 32 bit archs.

Since PHP 8.1, the following expression causes a deprecation:
Types::DOMAIN_NAME | DomainName::FLAG_NO_COMPRESSION

PHP Deprecated: Implicit conversion from float 2147483648 to int loses precision

This PR fixes the issue by shifting FLAG_NO_COMPRESSION by 16 bits.

It also skips a comparison in Long::setValue() that doesn't need to happen on 32b archs, where numbers are always 32b and can be negative even if they're meant to be understood as unsigned longs. Encoding/decoding doesn't care about the sign since they use pack/unpack().

@stof
Copy link

stof commented Sep 19, 2022

@kelunik This PR fixes a deprecation warning when using amphp in the Symfony testsuite

Comment on lines +41 to 47
if (4 !== \PHP_INT_SIZE) {
if ($value < 0) {
throw new \UnderflowException('Long integer value must be in the range 0 - 4294967296');
} else if ($value > 0xffffffff) {
throw new \OverflowException('Long integer value must be in the range 0 - 4294967296');
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we're on 32 bit, values that should be positive (unsigned) will be negative, no?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On 32-bit, we won't enter this branch because of the 4 !== \PHP_INT_SIZE check above.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know, but values decoding to large values will be negative on 32 bit, no? Shouldn't we reject those?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nevermind, I guess it's fine that way.

class DomainName extends Type
{
const FLAG_NO_COMPRESSION = 0x80000000;
const FLAG_NO_COMPRESSION = 0x8000;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Technically, this is a BC break. Should we just fix the usage and leave this as is?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line is the culprit, php triggers the deprecation on this very line. It's a too big number on 32bit.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See #28, WDYT?

@kelunik
Copy link
Collaborator

kelunik commented Sep 19, 2022

@stof Thanks for the reminder, seems like we've missed this!

@nicolas-grekas
Copy link
Author

Closing in favor of #28

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

Successfully merging this pull request may close these issues.

3 participants