From f1283582f16b2176050f954aac20942278d25fe4 Mon Sep 17 00:00:00 2001 From: manuel Date: Wed, 24 Sep 2025 16:36:47 +0200 Subject: [PATCH] Fix GH-17951: memory_limit ini value not being overwritten by max_memory_limit Make sure to always duplicate max_memory_limit ini value. Otherwise the alter ini routine may assume the value hasn't been overwritten, resulting in the user-specified value being set after the on_modify handler has run. --- main/main.c | 2 +- tests/basic/gh17951_runtime_change_6.phpt | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 tests/basic/gh17951_runtime_change_6.phpt diff --git a/main/main.c b/main/main.c index e33ef29d61bb7..cfa84ba0959bb 100644 --- a/main/main.c +++ b/main/main.c @@ -346,7 +346,7 @@ static PHP_INI_MH(OnChangeMemoryLimit) } zend_ini_entry *max_mem_limit_ini = zend_hash_str_find_ptr(EG(ini_directives), ZEND_STRL("max_memory_limit")); - entry->value = zend_string_copy(max_mem_limit_ini->value); + entry->value = zend_string_init(ZSTR_VAL(max_mem_limit_ini->value), ZSTR_LEN(max_mem_limit_ini->value), true); PG(memory_limit) = PG(max_memory_limit); return SUCCESS; diff --git a/tests/basic/gh17951_runtime_change_6.phpt b/tests/basic/gh17951_runtime_change_6.phpt new file mode 100644 index 0000000000000..0c62b0e837474 --- /dev/null +++ b/tests/basic/gh17951_runtime_change_6.phpt @@ -0,0 +1,19 @@ +--TEST-- +GH-17951 Runtime Change 6 +--INI-- +memory_limit=128M +max_memory_limit=512M +--FILE-- + +--EXPECTF-- +Warning: Failed to set memory_limit to 1073741824 bytes. Setting to max_memory_limit instead (currently: 536870912 bytes) in %s on line %d +512M +Warning: Failed to set memory_limit to 1073741824 bytes. Setting to max_memory_limit instead (currently: 536870912 bytes) in %s on line %d +512M +Warning: Failed to set memory_limit to 1073741824 bytes. Setting to max_memory_limit instead (currently: 536870912 bytes) in %s on line %d +512M