Commit a1948aca216 for php

commit a1948aca216f804c17a4b496056596da3986c474
Author: Arnaud Le Blanc <365207+arnaud-lb@users.noreply.github.com>
Date:   Fri Nov 20 16:32:03 2026 +0100

    Replace some fatals by hard exits (#25626)

diff --git a/Zend/zend_alloc.c b/Zend/zend_alloc.c
index 2b52babc98e..f5bf3a001b4 100644
--- a/Zend/zend_alloc.c
+++ b/Zend/zend_alloc.c
@@ -480,10 +480,18 @@ ZEND_COLD void zend_mm_oom_info_dtor(zend_oom_info *info)
 	}
 }

-#ifdef ZEND_MM_LIMIT
-ZEND_NORETURN static ZEND_COLD void zend_mm_hard_limit_error(zend_mm_heap *heap,
-		size_t add_size ZEND_FILE_LINE_DC)
+ZEND_NORETURN ZEND_API ZEND_COLD void zend_mm_unrecoverable_error(const char *format, ...)
 {
+	va_list args;
+	va_start(args, format);
+
+	char buf[1024];
+	if (vsnprintf(buf, sizeof(buf), format, args) < 0) {
+		abort();
+	}
+
+	va_end(args);
+
 	zend_string *script_filename = NULL;
 	uint32_t script_lineno = 0;

@@ -500,24 +508,25 @@ ZEND_NORETURN static ZEND_COLD void zend_mm_hard_limit_error(zend_mm_heap *heap,
 		script_lineno = 0;
 	}

-	fprintf(stderr,
+	fprintf(stderr, "%s in %s on line %" PRIu32 "\n", buf, ZSTR_VAL(script_filename), script_lineno);
+	fflush(stderr);
+
+	_exit(137);
+}
+
+#ifdef ZEND_MM_LIMIT
+ZEND_NORETURN static ZEND_COLD void zend_mm_hard_limit_error(zend_mm_heap *heap,
+		size_t add_size ZEND_FILE_LINE_DC)
+{
+	zend_mm_unrecoverable_error(
 # if ZEND_DEBUG
-			"Hard memory limit of %zu bytes exhausted at %s:%d (tried to allocate %zu bytes) in %s on line %d\n",
+			"Hard memory limit of %zu bytes exhausted at %s:%d (tried to allocate %zu bytes)",
 # else
-			"Hard memory limit of %zu bytes exhausted (tried to allocate %zu bytes) in %s on line %d\n",
+			"Hard memory limit of %zu bytes exhausted (tried to allocate %zu bytes)",
 # endif
 			heap->hard_limit
 			ZEND_FILE_LINE_RELAY_CC,
-			add_size,
-			ZSTR_VAL(script_filename),
-			script_lineno);
-
-	/* See http://support.microsoft.com/kb/190351 */
-# ifdef ZEND_WIN32
-	fflush(stderr);
-# endif
-
-	_exit(137);
+			add_size);
 }
 #endif /* ZEND_MM_LIMIT */

diff --git a/Zend/zend_alloc.h b/Zend/zend_alloc.h
index a8e5c3fa602..98f0c83a3ed 100644
--- a/Zend/zend_alloc.h
+++ b/Zend/zend_alloc.h
@@ -381,6 +381,8 @@ ZEND_COLD void zend_mm_oom_info_dtor(zend_oom_info *info);
 ZEND_API void zend_mm_set_max_allocs(uint64_t max_allocs);
 ZEND_API bool zend_mm_max_allocs_hit(void);

+ZEND_NORETURN ZEND_API ZEND_COLD void zend_mm_unrecoverable_error(const char *format, ...) ZEND_ATTRIBUTE_FORMAT(printf, 1, 2);
+
 /*

 // The following example shows how to use zend_mm_heap API with custom storage
diff --git a/Zend/zend_arena.h b/Zend/zend_arena.h
index 9b917a47e92..2cec9f4cbd4 100644
--- a/Zend/zend_arena.h
+++ b/Zend/zend_arena.h
@@ -83,7 +83,7 @@ static zend_always_inline void* zend_arena_calloc(zend_arena **arena_ptr, size_t

 	size = zend_safe_address(unit_size, count, 0, &overflow);
 	if (UNEXPECTED(overflow)) {
-		zend_error_noreturn(E_ERROR, "Possible integer overflow in zend_arena_calloc() (%zu * %zu)", unit_size, count);
+		zend_mm_unrecoverable_error("Possible integer overflow in zend_arena_calloc() (%zu * %zu)", unit_size, count);
 	}
 	ret = zend_arena_alloc(arena_ptr, size);
 	memset(ret, 0, size);
@@ -179,7 +179,7 @@ static zend_always_inline void* zend_arena_calloc(zend_arena **arena_ptr, size_t

 	size = zend_safe_address(unit_size, count, 0, &overflow);
 	if (UNEXPECTED(overflow)) {
-		zend_error_noreturn(E_ERROR, "Possible integer overflow in zend_arena_calloc() (%zu * %zu)", unit_size, count);
+		zend_mm_unrecoverable_error("Possible integer overflow in zend_arena_calloc() (%zu * %zu)", unit_size, count);
 	}
 	ret = zend_arena_alloc(arena_ptr, size);
 	memset(ret, 0, size);
diff --git a/Zend/zend_list.c b/Zend/zend_list.c
index 4e96ce0ec7d..bb913cd734c 100644
--- a/Zend/zend_list.c
+++ b/Zend/zend_list.c
@@ -36,7 +36,7 @@ ZEND_API zval* ZEND_FASTCALL zend_list_insert(void *ptr, int type)
 	if (index == 0) {
 		index = 1;
 	} else if (index == ZEND_LONG_MAX) {
-		zend_error_noreturn(E_ERROR, "Resource ID space overflow");
+		zend_mm_unrecoverable_error("Resource ID space overflow");
 	}
 	ZVAL_NEW_RES(&zv, index, ptr, type);
 	return zend_hash_index_add_new(&EG(regular_list), index, &zv);
diff --git a/Zend/zend_multiply.h b/Zend/zend_multiply.h
index 253e069eb74..23dcf7fc84e 100644
--- a/Zend/zend_multiply.h
+++ b/Zend/zend_multiply.h
@@ -340,7 +340,7 @@ static zend_always_inline size_t zend_safe_address_guarded(size_t nmemb, size_t
 	size_t ret = zend_safe_address(nmemb, size, offset, &overflow);

 	if (UNEXPECTED(overflow)) {
-		zend_error_noreturn(E_ERROR, "Possible integer overflow in memory allocation (%zu * %zu + %zu)", nmemb, size, offset);
+		zend_mm_unrecoverable_error("Possible integer overflow in memory allocation (%zu * %zu + %zu)", nmemb, size, offset);
 	}
 	return ret;
 }
@@ -352,7 +352,7 @@ static zend_always_inline size_t zend_safe_addmult(size_t nmemb, size_t size, si
 	size_t ret = zend_safe_address(nmemb, size, offset, &overflow);

 	if (UNEXPECTED(overflow)) {
-		zend_error_noreturn(E_ERROR, "Possible integer overflow in %s (%zu * %zu + %zu)", message, nmemb, size, offset);
+		zend_mm_unrecoverable_error("Possible integer overflow in %s (%zu * %zu + %zu)", message, nmemb, size, offset);
 	}
 	return ret;
 }
diff --git a/Zend/zend_smart_str.c b/Zend/zend_smart_str.c
index d28f3e66d8f..852c297ab8b 100644
--- a/Zend/zend_smart_str.c
+++ b/Zend/zend_smart_str.c
@@ -193,7 +193,7 @@ ZEND_API void ZEND_FASTCALL _smart_string_alloc_persistent(smart_string *str, si
 		str->c = pemalloc(str->a + 1, 1);
 	} else {
 		if (UNEXPECTED((size_t) len > SIZE_MAX - str->len)) {
-			zend_error_noreturn(E_ERROR, "String size overflow");
+			zend_mm_unrecoverable_error("String size overflow");
 		}
 		len += str->len;
 		str->a = ZEND_MM_ALIGNED_SIZE_EX(len + SMART_STRING_OVERHEAD, SMART_STRING_PAGE) - SMART_STRING_OVERHEAD;
@@ -219,7 +219,7 @@ ZEND_API void ZEND_FASTCALL _smart_string_alloc(smart_string *str, size_t len)
 		}
 	} else {
 		if (UNEXPECTED((size_t) len > SIZE_MAX - str->len)) {
-			zend_error_noreturn(E_ERROR, "String size overflow");
+			zend_mm_unrecoverable_error("String size overflow");
 		}
 		len += str->len;
 		str->a = ZEND_MM_ALIGNED_SIZE_EX(len + SMART_STRING_OVERHEAD, SMART_STRING_PAGE) - SMART_STRING_OVERHEAD;
diff --git a/Zend/zend_strtod.c b/Zend/zend_strtod.c
index 4a81d20e358..84437789812 100644
--- a/Zend/zend_strtod.c
+++ b/Zend/zend_strtod.c
@@ -587,7 +587,7 @@ Balloc
 		rv = (Bigint *)MALLOC(sizeof(Bigint) + (x-1)*sizeof(ULong));
 		if (!rv) {
 			FREE_DTOA_LOCK(0);
-			zend_error_noreturn(E_ERROR, "Balloc() failed to allocate memory");
+			zend_mm_unrecoverable_error("Balloc() failed to allocate memory");
 		}
 #else
 		len = (sizeof(Bigint) + (x-1)*sizeof(ULong) + sizeof(double) - 1)
@@ -600,7 +600,7 @@ Balloc
 			rv = (Bigint*)MALLOC(len*sizeof(double));
 			if (!rv) {
 				FREE_DTOA_LOCK(0);
-				zend_error_noreturn(E_ERROR, "Balloc() failed to allocate memory");
+				zend_mm_unrecoverable_error("Balloc() failed to allocate memory");
 			}
 #endif
 		rv->k = k;
diff --git a/Zend/zend_vm_def.h b/Zend/zend_vm_def.h
index 625ded38009..bc9163d3ba0 100644
--- a/Zend/zend_vm_def.h
+++ b/Zend/zend_vm_def.h
@@ -410,7 +410,7 @@ ZEND_VM_HANDLER(8, ZEND_CONCAT, CONST|TMP|CV, CONST|TMP|CV, SPEC(NO_CONST_CONST)
 			size_t len = ZSTR_LEN(op1_str);

 			if (UNEXPECTED(len > ZSTR_MAX_LEN - ZSTR_LEN(op2_str))) {
-				zend_error_noreturn(E_ERROR, "Integer overflow in memory allocation");
+				zend_mm_unrecoverable_error("Integer overflow in memory allocation");
 			}
 			str = zend_string_extend(op1_str, len + ZSTR_LEN(op2_str), 0);
 			memcpy(ZSTR_VAL(str) + len, ZSTR_VAL(op2_str), ZSTR_LEN(op2_str)+1);
diff --git a/Zend/zend_vm_execute.h b/Zend/zend_vm_execute.h
index df67ee29c61..4e2557f2086 100644
Binary files a/Zend/zend_vm_execute.h and b/Zend/zend_vm_execute.h differ
diff --git a/ext/pgsql/pgsql.c b/ext/pgsql/pgsql.c
index 64d3b61d18d..239b069c6ef 100644
--- a/ext/pgsql/pgsql.c
+++ b/ext/pgsql/pgsql.c
@@ -3638,7 +3638,7 @@ PHP_FUNCTION(pg_unescape_bytea)

 	tmp = (char *)PQunescapeBytea((unsigned char*)from, &to_len);
 	if (!tmp) {
-		zend_error_noreturn(E_ERROR, "Out of memory");
+		zend_mm_unrecoverable_error("Out of memory");
 	}

 	RETVAL_STRINGL(tmp, to_len);
@@ -3822,7 +3822,7 @@ PHP_FUNCTION(pg_connection_reset)
 	pgsql = link->conn;

 	PQreset(pgsql);
-
+
 	RETURN_BOOL(PQstatus(pgsql) != CONNECTION_BAD);
 }
 /* }}} */
@@ -5124,7 +5124,7 @@ PHP_PGSQL_API zend_result php_pgsql_convert(PGconn *pg_link, const zend_string *
 				PGSQL_CONV_CHECK_IGNORE();
 				if (err) {
 					if (escape_err) {
-						php_error_docref(NULL, E_NOTICE,
+						php_error_docref(NULL, E_NOTICE,
 							"String value escaping failed for PostgreSQL '%pS' (%pS)",
 							Z_STR_P(type), field);
 					} else {