php-src/ext
Tim Düsterhus ab5491f505
Fix shift in rand_rangeXX() (#9088)
The previous shifting logic is problematic for two reasons:

1. It invokes undefined behavior when the `->last_generated_size` is at least
as large as the target integer in `result`, because the shift is larger than
the target integer. This was reported in GH-9083.

2. It expands the returned bytes in a big-endian fashion: Earlier bytes are
shifting into the most-significant position. As all the other logic in the
random extension treats byte-strings as little-endian numbers this is
inconsistent.

By fixing the second issue, we can implicitly fix the first one: Instead of
shifting the existing bits by the number of "newly added" bits, we shift the
newly added bits by the number of existing bits. As we stop requesting new bits
once the total_size reached the size of the target integer we can be sure to
never invoke undefined behavior during shifting.

The get_int_user.phpt test was adjusted to verify the little-endian behavior.
It generates a single byte per call and we expect the first byte generated to
appear at the start of the resulting number.

see GH-9056 for a previous fix in the same area.
Fixes GH-9083 which reports the undefined behavior.
Resolves GH-9085 which was an alternative attempt to fix GH-9083.
2022-07-22 10:45:17 +01:00
..
bcmath Deprecate zend_atol() / add zend_ini_parse_quantity() (#7951) 2022-06-17 14:12:53 +02:00
bz2 Merge branch 'PHP-8.1' 2022-06-25 07:40:19 +01:00
calendar Rename @cname to @cvalue in stubs (#9043) 2022-07-19 15:11:42 +02:00
com_dotnet Rename @cname to @cvalue in stubs (#9043) 2022-07-19 15:11:42 +02:00
ctype
curl Convert return type of various object handlers from int to zend_result (#8755) 2022-06-26 01:00:19 +02:00
date Merge branch 'PHP-8.1' 2022-07-21 12:32:40 +01:00
dba [skip ci] Add comment about LMDB env_close function call 2022-07-21 14:48:25 +01:00
dl_test Add clean_module_functions() (#8763) 2022-06-17 16:33:20 +02:00
dom Rename @cname to @cvalue in stubs (#9043) 2022-07-19 15:11:42 +02:00
enchant Rename @cname to @cvalue in stubs (#9043) 2022-07-19 15:11:42 +02:00
exif Rename @cname to @cvalue in stubs (#9043) 2022-07-19 15:11:42 +02:00
ffi Rename @cname to @cvalue in stubs (#9043) 2022-07-19 15:11:42 +02:00
fileinfo Rename @cname to @cvalue in stubs (#9043) 2022-07-19 15:11:42 +02:00
filter Rename @cname to @cvalue in stubs (#9043) 2022-07-19 15:11:42 +02:00
ftp Rename @cname to @cvalue in stubs (#9043) 2022-07-19 15:11:42 +02:00
gd Improve tests on 32bit 2022-06-29 14:04:40 +02:00
gettext
gmp Rename @cname to @cvalue in stubs (#9043) 2022-07-19 15:11:42 +02:00
hash Rename @cname to @cvalue in stubs (#9043) 2022-07-19 15:11:42 +02:00
iconv Rename @cname to @cvalue in stubs (#9043) 2022-07-19 15:11:42 +02:00
imap Rename @cname to @cvalue in stubs (#9043) 2022-07-19 15:11:42 +02:00
intl Merge branch 'PHP-8.0' into PHP-8.1 2022-07-08 17:39:05 +01:00
json Rename @cname to @cvalue in stubs (#9043) 2022-07-19 15:11:42 +02:00
ldap Rename @cname to @cvalue in stubs (#9043) 2022-07-19 15:11:42 +02:00
libxml Rename @cname to @cvalue in stubs (#9043) 2022-07-19 15:11:42 +02:00
mbstring Merge branch 'PHP-8.1' 2022-07-20 17:01:42 +02:00
mysqli Rename @cname to @cvalue in stubs (#9043) 2022-07-19 15:11:42 +02:00
mysqlnd Merge branch 'PHP-8.1' 2022-06-10 12:45:30 -04:00
oci8 Fix RC debug of stub attribute (#9082) 2022-07-21 15:06:04 +02:00
odbc Declare ext/odbc constants in stubs (#9045) 2022-07-20 11:49:22 +02:00
opcache [ci skip] Fix typo (proloading → preloading) 2022-07-21 12:35:15 +02:00
openssl Declare ext/openssl constants in stubs (#9046) 2022-07-20 15:40:10 +02:00
pcntl Prevent fiber switching in tick function and signal handlers (#9028) 2022-07-16 13:05:16 -05:00
pcre Declare ext/pcre constants in stubs (#9077) 2022-07-21 13:21:02 +02:00
pdo Declare ext/pdo constants in stubs (#9078) 2022-07-22 09:46:47 +02:00
pdo_dblib
pdo_firebird Fix GH-8576: Bad interpretation of length when char is UTF-8 2022-07-12 11:57:25 +02:00
pdo_mysql Fix debug output 2022-06-09 13:42:45 +02:00
pdo_oci
pdo_odbc Merge branch 'PHP-8.1' 2022-06-13 14:44:49 +02:00
pdo_pgsql Remove SIZEOF_OFF_T undef in PDO PGSQL driver (#8301) 2022-06-09 13:29:20 +01:00
pdo_sqlite Drop support for SQLITE_COPY in authorizer callback 2022-07-19 10:55:50 +02:00
pgsql Add missing EXTENSIONS section to new test 2022-06-06 12:21:25 +02:00
phar phpinfo HTML Output: Make module title names clickable and link to the URL fragment 2022-07-20 17:18:34 +02:00
posix
pspell
random Fix shift in rand_rangeXX() (#9088) 2022-07-22 10:45:17 +01:00
readline
reflection Implement Random Extension 2022-07-19 10:27:38 +01:00
session Implement Random Extension 2022-07-19 10:27:38 +01:00
shmop
simplexml Convert return type of various object handlers from int to zend_result (#8755) 2022-06-26 01:00:19 +02:00
skeleton
snmp Drop remaining usage of u_char in favour of standard C99 uint8_t (#8611) 2022-05-23 21:57:31 +01:00
soap Implement Random Extension 2022-07-19 10:27:38 +01:00
sockets Sockets disable zerocopy test on ppc based arch. 2022-07-21 13:36:49 +01:00
sodium add SensitiveParameter as known string and use it in arginfo 2022-07-18 11:43:33 +02:00
spl Assert all test files are cleaned up in CI (#8977) 2022-07-21 16:06:14 +01:00
sqlite3 Allow user to change SQLITE_DEFENSIVE if needed 2022-04-11 17:08:48 +02:00
standard phpinfo HTML Output: Make module title names clickable and link to the URL fragment 2022-07-20 17:18:34 +02:00
sysvmsg
sysvsem
sysvshm Fix value in test case 2022-05-16 14:47:02 +02:00
tidy Convert return type of various object handlers from int to zend_result (#8755) 2022-06-26 01:00:19 +02:00
tokenizer Collapse more generated files in PRs (#8754) 2022-06-12 10:56:35 +02:00
xml Refactor php_next_utf8_char() to use zend_result 2022-03-13 13:48:21 +00:00
xmlreader
xmlwriter Initialise zend_stat_t to fix MSAN build 2022-05-22 16:06:27 +01:00
xsl
zend_test Fix RC debug of stub attribute (#9082) 2022-07-21 15:06:04 +02:00
zip add SensitiveParameter as known string and use it in arginfo 2022-07-18 11:43:33 +02:00
zlib Merge branch 'PHP-8.1' 2022-06-25 07:40:19 +01:00
ext_skel.php