[php-src] master: Merge branch 'PHP-8.4' into PHP-8.5

From: Date: Mon, 26 Oct 2026 16:32:22 +0000
Subject: [php-src] master: Merge branch 'PHP-8.4' into PHP-8.5
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-142740@lists.php.net to get a copy of this message
Author: Arnaud Le Blanc (arnaud-lb) Date: 2026-10-26T17:31:26+01:00 Commit: https://github.com/php/php-src/commit/f5a9dfa7e351ac394d7e3d77404842ff04f8d7e4 Raw diff: https://github.com/php/php-src/commit/f5a9dfa7e351ac394d7e3d77404842ff04f8d7e4.diff Merge branch 'PHP-8.4' into PHP-8.5 * PHP-8.4: Fix unmapping of an unrelated range when the aligned chunk mmap fails (#24542) Changed paths: A Zend/tests/zend_mm_chunk_alloc_mmap_failure.phpt M NEWS M Zend/zend_alloc.c Diff: diff --git a/NEWS b/NEWS index b53e372d033c..6254d1807c39 100644 --- a/NEWS +++ b/NEWS @@ -25,6 +25,8 @@ PHP NEWS . Fix memory leak for nested HTTP calls. (EdmondDantes) . Fix function and constant imports in compile_to_ast and add support for grouping. (Klaas Skelte van der Werf) + . Fixed unmapping of an unrelated range when the aligned chunk mmap fails + (Marti2203). - Date: . Fixed bug GH-20503 (Assertion failure with ext/date DateInterval property diff --git a/Zend/tests/zend_mm_chunk_alloc_mmap_failure.phpt b/Zend/tests/zend_mm_chunk_alloc_mmap_failure.phpt new file mode 100644 index 000000000000..b137f25620c5 --- /dev/null +++ b/Zend/tests/zend_mm_chunk_alloc_mmap_failure.phpt @@ -0,0 +1,32 @@ +--TEST-- +Failed retry mmap() in zend_mm_chunk_alloc_int() must not unmap an unrelated range +--EXTENSIONS-- +posix +--SKIPIF-- +<?php +if (PHP_OS_FAMILY !== 'Linux') die('skip Linux only'); +if (PHP_INT_SIZE != 8) die('skip this test is for 64bit platforms only'); +if (getenv('USE_ZEND_ALLOC') === '0') die('skip Zend MM disabled'); +$maps = @file_get_contents('/proc/self/maps'); +if ($maps === false) die('skip /proc/self/maps not available'); +if (!preg_match('/^([0-9a-f]+)-[0-9a-f]+ r-xp /m', $maps, $m) || hexdec($m[1]) > 0x40000000) { + die('skip only for non-PIE builds'); +} +?> +--INI-- +memory_limit=-1 +--FILE-- +<?php +// A huge block whose size equals the start of the executable mapping. If the +// first mmap() is not 2 MiB aligned and the retry fails under RLIMIT_AS, the +// missing NULL check used to unmap [size, size + 2 MiB - 4 KiB), i.e. our text. +preg_match('/^([0-9a-f]+)-[0-9a-f]+ r-xp /m', file_get_contents('/proc/self/maps'), $m); +$size = hexdec($m[1]); +preg_match('/VmSize:\s+(\d+)/', file_get_contents('/proc/self/status'), $m); +// Room for the first mmap() of $size bytes, not for the aligned retry. +var_dump(posix_setrlimit(POSIX_RLIMIT_AS, $m[1] * 1024 + $size + 1024 * 1024, POSIX_RLIMIT_INFINITY)); +$s = str_repeat('A', $size - 4096); +echo "allocation succeeded\n"; +?> +--EXPECTREGEX-- +bool\(true\)\s+(.*Out of memory|allocation succeeded)\s* diff --git a/Zend/zend_alloc.c b/Zend/zend_alloc.c index ba5a70287a4b..5a529ff08e37 100644 --- a/Zend/zend_alloc.c +++ b/Zend/zend_alloc.c @@ -899,6 +899,9 @@ static void *zend_mm_chunk_alloc_int(size_t size, size_t alignment) /* chunk has to be aligned */ zend_mm_munmap(ptr, size); ptr = zend_mm_mmap(size + alignment - REAL_PAGE_SIZE); + if (ptr == NULL) { + return NULL; + } #ifdef _WIN32 offset = ZEND_MM_ALIGNED_OFFSET(ptr, alignment); if (offset != 0) {

« previous php.cvs (#142740) next »