1
0
mirror of https://github.com/php/php-src.git synced 2026-04-10 09:33:06 +02:00
Files
Niels Dossche 87862835e2 Fix undefined behaviour in unpack()
atoi()'s return value is actually undefined when an underflow or
overflow occurs. For example on 32-bit on my system the overflow test
which inputs "h2147483648" results in repetitions==2147483647 and on
64-bit this gives repetitions==-2147483648. The reason the test works on
32-bit is because there's a second undefined behaviour problem:
in case 'h' when repetitions==2147483647, we add 1 and divide by 2.
This is signed-wrap undefined behaviour and accidentally triggers the
overflow check like we wanted to.

Avoid all this trouble and use strtol with explicit error checking.

This also fixes a semantic bug where repetitions==INT_MAX would result
in the overflow check to trigger, even though there is no overflow.

Closes GH-10943.
2023-03-28 22:43:27 +02:00
..
2022-08-30 16:52:33 +02:00
2021-08-17 11:32:24 +02:00
2021-08-19 10:39:23 +02:00
2023-03-27 16:33:36 +02:00
2022-08-18 12:30:45 +02:00
2021-07-16 10:07:35 +02:00
2022-11-07 15:07:09 +01:00
2023-03-27 16:33:36 +02:00