91119[TASK] Avoid `not representable as an int, cast occurred ` PHP85 warning
Commit message
Review
-
Code review CR 0
-
Verified V 0
- core-ci +1 CI
Issues 1
Files 2
Review log 1519
-
Stefan Bürk uploaded patch set 1 10/17/25, 08:36
-
Georg Ringer commented on patch set 1 10/17/25, 08:56
so why using a hexdec if we are using an integer only? why not generating a random int right away? -
Andreas Kienast commented on patch set 1 10/17/25, 08:57
Why don't we use `(int)floor($float)`? This should mimic the previous behavior and does not fiddle with error reporting. -
core-ci voted on patch set 1 V +1 10/17/25, 08:57 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/86878
-
Andreas Kienast commented on patch set 1 10/17/25, 09:00
Reply
Alright, just tested this with PHP 8.5: ``` php > var_dump(floor(1.4393998882452697E+19)); float(1.4393998882452697E+19) ``` What a weird handling... -
Stefan Bürk commented on patch set 1 10/17/25, 09:24
Reply
> floor(int|float $num): float Using floor() is not an option here, which would require a int or float value which would not work with a "string" and requring additional cast(s). Beside this, it returns a float so it would not avoid the issue with casting to int. I'd prefere the current solution, which is basically the same which Sebastian Bergman used in the one or other package and also others out there. Could find a better solution for this, but I'm open for it. What should we do ? @akienast@scripting-base.de -
Stefan Bürk rebased onto patch set 2
V +110/17/25, 09:25 -
core-ci voted on patch set 2 V +1 10/17/25, 09:42 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/86882
-
Stefan Bürk commented on patch set 2 10/17/25, 10:27
Reply
For `RecoveryCodes`: `hexdec()` returns the int reprecentation of the hex string, in case the value is to big it is returned as float, and I guess that was the reason why the `(int)` cast has been added in the first place. I would assume that we may change that here, either decreasing the hexstring length or using an other kind of "randomized integer" to mitigate the `hexdec() -> float -> int-cast` issue here, but I'm not really sure if there are impacts I do not see changing that. So far I understand the code this should be doable in some way. Maybe @ben@bnf.dev, @oliver.hader@typo3.org or @bo@cedev.de can have a look here for https://review.typo3.org/c/Packages/TYPO3.CMS/+/91119/2/typo3/sysext/core/Classes/Authentication/Mfa/Provider/RecoveryCodes.php#67 if that may be changed away from the hexstring/hexdec or at least reduced/lowered: ``` $number = @(int)hexdec($random->generateRandomHexString(16)); // We only want to work with positive integers if ($number < 0) { continue; } ``` -
Stefan Bürk commented on patch set 2 10/17/25, 10:38
Reply
Reducing to `15` instead of `16` for `generateRandomHexString()` would return `int` calling `hexdec()` and the `issue` casting a to "big" float should go away without the need to suppress it. I'd suggest to lower that here to ``` $number = @(int)hexdec($random->generateRandomHexString(12)); ``` to be on the safe side. However, I wonder what happens if the method is called with `length: 200` and what kind of codes are generated in that case (or if a max length check needs to be added like the min length check). -
Stefan Bürk rebased onto patch set 3
V +110/17/25, 16:23 -
core-ci voted on patch set 3 V +1 10/17/25, 16:32 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/86941
-
Oliver Klee updated the commit message in patch set 4
V +110/17/25, 19:14 -
core-ci voted on patch set 4 V +1 10/17/25, 19:24 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/86951
-
Oliver Hader commented on patch set 4 10/20/25, 11:26
Reply
It would be possible to use `random_int(0,9)` directly instead of converting a 64-bit word back to integer. `PHP_INT_MAX` (`9223372036854775807`) is just a 63-bit integer. -
Oliver Hader commented on patch set 4 10/20/25, 11:59
Reply
→ see https://review.typo3.org/c/Packages/TYPO3.CMS/+/91168 (which uses `random_int`) -
Oliver Hader commented on patch set 4 10/21/25, 13:50
Reply
Done -
Oliver Klee commented on patch set 4 10/21/25, 14:33
https://review.typo3.org/c/Packages/TYPO3.CMS/+/91188 for simplifying the other method -
Stefan Bürk abandoned the change 10/22/25, 12:38
resolved with dedicated changes in other ways. Not needed anymore.