1
0
mirror of https://github.com/php/php-src.git synced 2026-03-24 00:02:20 +01:00

Merge branch 'PHP-8.3' into PHP-8.4

* PHP-8.3:
  Fix GH-20620: bzcompress() overflow on large source size.
This commit is contained in:
David Carlier
2025-12-05 22:31:14 +00:00
3 changed files with 34 additions and 1 deletions

4
NEWS
View File

@@ -2,6 +2,10 @@ PHP NEWS
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
?? ??? ????, PHP 8.4.17
- Bz2:
. Fixed bug GH-20620 (bzcompress overflow on large source size).
(David Carlier)
- GD:
. Fixed bug GH-20622 (imagestring/imagestringup overflow). (David Carlier)

View File

@@ -458,7 +458,15 @@ PHP_FUNCTION(bzcompress)
+ .01 x length of data + 600 which is the largest size the results of the compression
could possibly be, at least that's what the libbz2 docs say (thanks to jeremy@nirvani.net
for pointing this out). */
dest_len = (unsigned int) (source_len + (0.01 * source_len) + 600);
size_t chunk_len = source_len + source_len / 100 + 600;
const size_t min = MIN(ZSTR_MAX_LEN, UINT_MAX);
if (chunk_len < source_len || chunk_len > min) {
zend_argument_value_error(1, "must have a length less than or equal to %zu", min);
RETURN_THROWS();
}
dest_len = (unsigned int) chunk_len;
/* Allocate the destination buffer */
dest = zend_string_alloc(dest_len, 0);

View File

@@ -0,0 +1,21 @@
--TEST--
Bug GH-20620 (bzcompress with large source)
--EXTENSIONS--
bz2
--SKIPIF--
<?php
if (PHP_INT_SIZE != 8) die('skip this test is for 64bit platforms only');
if (getenv('SKIP_SLOW_TESTS')) die('skip slow tests excluded by request');
?>
--INI--
memory_limit=-1
--FILE--
<?php
try {
bzcompress(str_repeat('1', 4295163906));
} catch (\ValueError $e) {
echo $e->getMessage(), PHP_EOL;
}
?>
--EXPECTF--
bzcompress(): Argument #1 ($data) must have a length less than or equal to %d