colinfrei / Symfony-Bitfield-Form-Type-Bundle

Symfony bundle that adds a form type for values saved as bitfields
4 stars 2 forks source link

Endless loop on 32-bit PHP #5

Closed ghost closed 9 years ago

ghost commented 9 years ago

When running this class on 32bit PHP there is an endless loop in BitfieldToArrayTransformer.php, line 16.

The reason for this is as follows: $currentBit is left-shifted until it reaches 0x40000000 (1 << 30). Since this is smaller than MAX_BITFIELDS_32 the loop is entered and the value is shifted once again (1 << 31). However, this is a negative number in 32-bit PHP (and therefore smaller than MAX_BITFIELDS_32), so the loop is entered again (and will produce a negative entry in $validBits if this bit was set in $bits). The value is shifted again and thereby shifted out of the range: (1 << 32) == 0 in 32-bit PHP. Since 0 is also smaller than MAX_BITFIELDS_32 the loop is entered again. So the loop shifts 0, finds that 0 is smaller than MAX_BITFIELDS_32 and so on.