From 327ad411abb72988f6efa4b9a5fc8a67d96a7e2e Mon Sep 17 00:00:00 2001 From: Calvin Buckley Date: Thu, 1 Oct 2026 16:15:37 -0300 Subject: [PATCH 1/7] sapi: remove default post reader There is only one of these; there's no point in the indirection here as it is never overrode, and set very early in main.c. Move the default post handling into the SAPI handling, and remove the pointless check if a default POST reader exists. This stuff was originally introduced in 98d95dd88eec996ad2608b357dd03bc7930b3fb4. --- main/SAPI.c | 25 +++++-------------------- main/SAPI.h | 4 ---- main/php_content_types.c | 13 ------------- main/php_content_types.h | 1 - 4 files changed, 5 insertions(+), 38 deletions(-) diff --git a/main/SAPI.c b/main/SAPI.c index f85c0a7c95a8..9f3c8862cb9d 100644 --- a/main/SAPI.c +++ b/main/SAPI.c @@ -182,13 +182,6 @@ SAPI_API void sapi_read_post_data(void) } else { /* fallback */ SG(request_info).post_entry = NULL; - if (UNEXPECTED(!sapi_module.default_post_reader)) { - /* this should not happen as there should always be a default_post_reader */ - SG(request_info).content_type_dup = NULL; - sapi_module.sapi_error(E_WARNING, "Unsupported content type: '%s'", content_type); - efree(content_type); - return; - } } if (oldchar) { *(p-1) = oldchar; @@ -201,8 +194,11 @@ SAPI_API void sapi_read_post_data(void) post_reader_func(); } - if(sapi_module.default_post_reader) { - sapi_module.default_post_reader(); + if (!strcmp(SG(request_info).request_method, "POST")) { + if (NULL == SG(request_info).post_entry) { + /* no post handler registered, so we just swallow the data */ + sapi_read_standard_form_data(); + } } } @@ -923,17 +919,6 @@ SAPI_API void sapi_unregister_post_entry(const sapi_post_entry *post_entry) post_entry->content_type_len); } - -SAPI_API zend_result sapi_register_default_post_reader(void (*default_post_reader)(void)) -{ - if (SG(sapi_started) && EG(current_execute_data)) { - return FAILURE; - } - sapi_module.default_post_reader = default_post_reader; - return SUCCESS; -} - - SAPI_API zend_result sapi_register_treat_data(void (*treat_data)(int arg, char *str, zval *destArray)) { if (SG(sapi_started) && EG(current_execute_data)) { diff --git a/main/SAPI.h b/main/SAPI.h index 373f13564e7b..6879918f5bc7 100644 --- a/main/SAPI.h +++ b/main/SAPI.h @@ -215,7 +215,6 @@ SAPI_API size_t sapi_read_post_block(char *buffer, size_t buflen); SAPI_API zend_result sapi_register_post_entries(const sapi_post_entry *post_entry); SAPI_API zend_result sapi_register_post_entry(const sapi_post_entry *post_entry); SAPI_API void sapi_unregister_post_entry(const sapi_post_entry *post_entry); -SAPI_API zend_result sapi_register_default_post_reader(void (*default_post_reader)(void)); SAPI_API zend_result sapi_register_treat_data(void (*treat_data)(int arg, char *str, zval *destArray)); SAPI_API zend_result sapi_register_input_filter(unsigned int (*input_filter)(int arg, const char *var, char **val, size_t val_len, size_t *new_val_len), unsigned int (*input_filter_init)(void)); @@ -260,7 +259,6 @@ struct _sapi_module_struct { char *php_ini_path_override; - void (*default_post_reader)(void); void (*treat_data)(int arg, char *str, zval *destArray); char *executable_location; @@ -306,14 +304,12 @@ struct _sapi_post_entry { BEGIN_EXTERN_C() SAPI_API SAPI_POST_READER_FUNC(sapi_read_standard_form_data); -SAPI_API SAPI_POST_READER_FUNC(php_default_post_reader); SAPI_API SAPI_TREAT_DATA_FUNC(php_default_treat_data); SAPI_API SAPI_INPUT_FILTER_FUNC(php_default_input_filter); END_EXTERN_C() #define STANDARD_SAPI_MODULE_PROPERTIES \ NULL, /* php_ini_path_override */ \ - NULL, /* default_post_reader */ \ NULL, /* treat_data */ \ NULL, /* executable_location */ \ 0, /* php_ini_ignore */ \ diff --git a/main/php_content_types.c b/main/php_content_types.c index 8609df308844..cdd7b561112e 100644 --- a/main/php_content_types.c +++ b/main/php_content_types.c @@ -24,22 +24,9 @@ static const sapi_post_entry php_post_entries[] = { }; /* }}} */ -/* {{{ SAPI_POST_READER_FUNC */ -SAPI_API SAPI_POST_READER_FUNC(php_default_post_reader) -{ - if (!strcmp(SG(request_info).request_method, "POST")) { - if (NULL == SG(request_info).post_entry) { - /* no post handler registered, so we just swallow the data */ - sapi_read_standard_form_data(); - } - } -} -/* }}} */ - /* {{{ php_startup_sapi_content_types */ void php_startup_sapi_content_types(void) { - sapi_register_default_post_reader(php_default_post_reader); sapi_register_treat_data(php_default_treat_data); sapi_register_input_filter(php_default_input_filter, NULL); } diff --git a/main/php_content_types.h b/main/php_content_types.h index 65786392f28b..aaaece55dab0 100644 --- a/main/php_content_types.h +++ b/main/php_content_types.h @@ -15,7 +15,6 @@ #define DEFAULT_POST_CONTENT_TYPE "application/x-www-form-urlencoded" -SAPI_API SAPI_POST_READER_FUNC(php_default_post_reader); SAPI_API SAPI_POST_HANDLER_FUNC(php_std_post_handler); void php_startup_sapi_content_types(void); int php_setup_sapi_content_types(void); From 3b971efec179f77c3aa7beec1935d09e0920e555 Mon Sep 17 00:00:00 2001 From: Calvin Buckley Date: Thu, 1 Oct 2026 16:45:20 -0300 Subject: [PATCH 2/7] sapi: move default php_post_entries into SAPI.c mbstring had a duplicate of this; remove some indirection and provide this as a symbol so it can be switched back to w/o duplication. --- ext/mbstring/mbstring.c | 8 -------- main/SAPI.c | 9 ++++++++- main/SAPI.h | 5 +++++ main/php_content_types.c | 17 ----------------- main/php_content_types.h | 1 - 5 files changed, 13 insertions(+), 27 deletions(-) diff --git a/ext/mbstring/mbstring.c b/ext/mbstring/mbstring.c index c754b0cfb56d..b3f38bbff399 100644 --- a/ext/mbstring/mbstring.c +++ b/ext/mbstring/mbstring.c @@ -208,14 +208,6 @@ zend_module_entry mbstring_module_entry = { }; /* }}} */ -/* {{{ static sapi_post_entry php_post_entries[] */ -static const sapi_post_entry php_post_entries[] = { - { DEFAULT_POST_CONTENT_TYPE, sizeof(DEFAULT_POST_CONTENT_TYPE)-1, sapi_read_standard_form_data, php_std_post_handler }, - { MULTIPART_CONTENT_TYPE, sizeof(MULTIPART_CONTENT_TYPE)-1, NULL, rfc1867_post_handler }, - { NULL, 0, NULL, NULL } -}; -/* }}} */ - #ifdef COMPILE_DL_MBSTRING #ifdef ZTS ZEND_TSRMLS_CACHE_DEFINE() diff --git a/main/SAPI.c b/main/SAPI.c index 9f3c8862cb9d..460ed9e207c7 100644 --- a/main/SAPI.c +++ b/main/SAPI.c @@ -52,7 +52,7 @@ static void sapi_globals_ctor(sapi_globals_struct *sapi_globals) { memset(sapi_globals, 0, sizeof(*sapi_globals)); zend_hash_init(&sapi_globals->known_post_content_types, 8, NULL, _type_dtor, 1); - php_setup_sapi_content_types(); + sapi_register_post_entries(php_post_entries); } static void sapi_globals_dtor(sapi_globals_struct *sapi_globals) @@ -881,6 +881,13 @@ SAPI_API zend_result sapi_send_headers(void) return ret; } +/* {{{ php_post_entries[] */ +const sapi_post_entry php_post_entries[] = { + { DEFAULT_POST_CONTENT_TYPE, sizeof(DEFAULT_POST_CONTENT_TYPE)-1, sapi_read_standard_form_data, php_std_post_handler }, + { MULTIPART_CONTENT_TYPE, sizeof(MULTIPART_CONTENT_TYPE)-1, NULL, rfc1867_post_handler }, + { NULL, 0, NULL, NULL } +}; +/* }}} */ SAPI_API zend_result sapi_register_post_entries(const sapi_post_entry *post_entries) { diff --git a/main/SAPI.h b/main/SAPI.h index 6879918f5bc7..2c81cb24018a 100644 --- a/main/SAPI.h +++ b/main/SAPI.h @@ -284,6 +284,11 @@ struct _sapi_post_entry { void (*post_handler)(char *content_type_dup, void *arg); }; +BEGIN_EXTERN_C() +/* Default POST entries to switch back to when overrode */ +extern SAPI_API const sapi_post_entry php_post_entries[]; +END_EXTERN_C() + /* header_handler() constants */ #define SAPI_HEADER_ADD (1<<0) diff --git a/main/php_content_types.c b/main/php_content_types.c index cdd7b561112e..6596383261b6 100644 --- a/main/php_content_types.c +++ b/main/php_content_types.c @@ -16,14 +16,6 @@ #include "php_content_types.h" -/* {{{ php_post_entries[] */ -static const sapi_post_entry php_post_entries[] = { - { DEFAULT_POST_CONTENT_TYPE, sizeof(DEFAULT_POST_CONTENT_TYPE)-1, sapi_read_standard_form_data, php_std_post_handler }, - { MULTIPART_CONTENT_TYPE, sizeof(MULTIPART_CONTENT_TYPE)-1, NULL, rfc1867_post_handler }, - { NULL, 0, NULL, NULL } -}; -/* }}} */ - /* {{{ php_startup_sapi_content_types */ void php_startup_sapi_content_types(void) { @@ -31,12 +23,3 @@ void php_startup_sapi_content_types(void) sapi_register_input_filter(php_default_input_filter, NULL); } /* }}} */ - -/* {{{ php_setup_sapi_content_types */ -int php_setup_sapi_content_types(void) -{ - sapi_register_post_entries(php_post_entries); - - return SUCCESS; -} -/* }}} */ diff --git a/main/php_content_types.h b/main/php_content_types.h index aaaece55dab0..c7eeab489452 100644 --- a/main/php_content_types.h +++ b/main/php_content_types.h @@ -17,6 +17,5 @@ SAPI_API SAPI_POST_HANDLER_FUNC(php_std_post_handler); void php_startup_sapi_content_types(void); -int php_setup_sapi_content_types(void); #endif /* PHP_CONTENT_TYPES_H */ From ac1e85063e7bfe41a793b667912005ebf0ee05f5 Mon Sep 17 00:00:00 2001 From: Calvin Buckley Date: Thu, 1 Oct 2026 16:55:38 -0300 Subject: [PATCH 3/7] sapi: Move DEFAULT_POST_CONTENT_TYPE into SAPI.h --- main/SAPI.h | 2 ++ main/php_content_types.h | 2 -- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/main/SAPI.h b/main/SAPI.h index 2c81cb24018a..724cc4e7b325 100644 --- a/main/SAPI.h +++ b/main/SAPI.h @@ -307,6 +307,8 @@ END_EXTERN_C() #define SAPI_TREAT_DATA_FUNC(treat_data) void treat_data(int arg, char *str, zval* destArray) #define SAPI_INPUT_FILTER_FUNC(input_filter) unsigned int input_filter(int arg, const char *var, char **val, size_t val_len, size_t *new_val_len) +#define DEFAULT_POST_CONTENT_TYPE "application/x-www-form-urlencoded" + BEGIN_EXTERN_C() SAPI_API SAPI_POST_READER_FUNC(sapi_read_standard_form_data); SAPI_API SAPI_TREAT_DATA_FUNC(php_default_treat_data); diff --git a/main/php_content_types.h b/main/php_content_types.h index c7eeab489452..f5b180104b05 100644 --- a/main/php_content_types.h +++ b/main/php_content_types.h @@ -13,8 +13,6 @@ #ifndef PHP_CONTENT_TYPES_H #define PHP_CONTENT_TYPES_H -#define DEFAULT_POST_CONTENT_TYPE "application/x-www-form-urlencoded" - SAPI_API SAPI_POST_HANDLER_FUNC(php_std_post_handler); void php_startup_sapi_content_types(void); From 1590041aee5a242bd27e59c5f5f86898021d028c Mon Sep 17 00:00:00 2001 From: Calvin Buckley Date: Thu, 1 Oct 2026 16:56:31 -0300 Subject: [PATCH 4/7] sapi: Remove indirection for treat data/input filter init --- main/main.c | 4 +++- main/php_content_types.c | 7 ------- main/php_content_types.h | 1 - 3 files changed, 3 insertions(+), 9 deletions(-) diff --git a/main/main.c b/main/main.c index 0267c6839137..5e39d3aa622d 100644 --- a/main/main.c +++ b/main/main.c @@ -2358,7 +2358,9 @@ zend_result php_module_startup(sapi_module_struct *sf, zend_module_entry *additi zuv.html_errors = 1; php_startup_auto_globals(); zend_set_utility_values(&zuv); - php_startup_sapi_content_types(); + + sapi_register_treat_data(php_default_treat_data); + sapi_register_input_filter(php_default_input_filter, NULL); /* Begin to fingerprint the process state */ zend_startup_system_id(); diff --git a/main/php_content_types.c b/main/php_content_types.c index 6596383261b6..5df0148cb69b 100644 --- a/main/php_content_types.c +++ b/main/php_content_types.c @@ -16,10 +16,3 @@ #include "php_content_types.h" -/* {{{ php_startup_sapi_content_types */ -void php_startup_sapi_content_types(void) -{ - sapi_register_treat_data(php_default_treat_data); - sapi_register_input_filter(php_default_input_filter, NULL); -} -/* }}} */ diff --git a/main/php_content_types.h b/main/php_content_types.h index f5b180104b05..e05b5161d3b4 100644 --- a/main/php_content_types.h +++ b/main/php_content_types.h @@ -14,6 +14,5 @@ #define PHP_CONTENT_TYPES_H SAPI_API SAPI_POST_HANDLER_FUNC(php_std_post_handler); -void php_startup_sapi_content_types(void); #endif /* PHP_CONTENT_TYPES_H */ From f4aeaf25ac13cbedc8317ffd44a38f5397174f19 Mon Sep 17 00:00:00 2001 From: Calvin Buckley Date: Thu, 1 Oct 2026 17:02:28 -0300 Subject: [PATCH 5/7] sapi: Eliminate php_content_types All its contents have been folded elsewhere. XXX: Perhaps php_std_post_handler belongs in php_variables.h? --- configure.ac | 1 - ext/mbstring/mbstring.c | 1 - main/SAPI.c | 2 -- main/SAPI.h | 1 + main/main.c | 1 - main/php_content_types.c | 18 ------------------ main/php_content_types.h | 18 ------------------ main/php_variables.c | 1 - win32/build/config.w32 | 2 +- 9 files changed, 2 insertions(+), 43 deletions(-) delete mode 100644 main/php_content_types.c delete mode 100644 main/php_content_types.h diff --git a/configure.ac b/configure.ac index 40675011a2c0..e05987488a9b 100644 --- a/configure.ac +++ b/configure.ac @@ -1660,7 +1660,6 @@ PHP_ADD_SOURCES([main], m4_normalize([ main.c network.c output.c - php_content_types.c php_ini_builder.c php_ini.c php_glob.c diff --git a/ext/mbstring/mbstring.c b/ext/mbstring/mbstring.c index b3f38bbff399..3cf7a3b6d425 100644 --- a/ext/mbstring/mbstring.c +++ b/ext/mbstring/mbstring.c @@ -46,7 +46,6 @@ #include "php_globals.h" #include "rfc1867.h" -#include "php_content_types.h" #include "SAPI.h" #include "php_unicode.h" #include "TSRM.h" diff --git a/main/SAPI.c b/main/SAPI.c index 460ed9e207c7..fe00f843f5ff 100644 --- a/main/SAPI.c +++ b/main/SAPI.c @@ -33,8 +33,6 @@ #include "rfc1867.h" -#include "php_content_types.h" - #ifdef ZTS SAPI_API int sapi_globals_id; ZEND_TLS_API TSRM_TLS TSRM_TLS_MODEL_ATTR sapi_globals_struct sapi_globals; diff --git a/main/SAPI.h b/main/SAPI.h index 724cc4e7b325..9c81c2fc25f8 100644 --- a/main/SAPI.h +++ b/main/SAPI.h @@ -310,6 +310,7 @@ END_EXTERN_C() #define DEFAULT_POST_CONTENT_TYPE "application/x-www-form-urlencoded" BEGIN_EXTERN_C() +SAPI_API SAPI_POST_HANDLER_FUNC(php_std_post_handler); SAPI_API SAPI_POST_READER_FUNC(sapi_read_standard_form_data); SAPI_API SAPI_TREAT_DATA_FUNC(php_default_treat_data); SAPI_API SAPI_INPUT_FILTER_FUNC(php_default_input_filter); diff --git a/main/main.c b/main/main.c index 5e39d3aa622d..d8953b3b764f 100644 --- a/main/main.c +++ b/main/main.c @@ -80,7 +80,6 @@ #include "zend_smart_string.h" #include "zend_smart_str.h" -#include "php_content_types.h" #include "php_ticks.h" #include "php_streams.h" #include "php_open_temporary_file.h" diff --git a/main/php_content_types.c b/main/php_content_types.c deleted file mode 100644 index 5df0148cb69b..000000000000 --- a/main/php_content_types.c +++ /dev/null @@ -1,18 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | Copyright © The PHP Group and Contributors. | - +----------------------------------------------------------------------+ - | This source file is subject to the Modified BSD License that is | - | bundled with this package in the file LICENSE, and is available | - | through the World Wide Web at . | - | | - | SPDX-License-Identifier: BSD-3-Clause | - +----------------------------------------------------------------------+ -*/ - -#include "php.h" -#include "SAPI.h" -#include "rfc1867.h" - -#include "php_content_types.h" - diff --git a/main/php_content_types.h b/main/php_content_types.h deleted file mode 100644 index e05b5161d3b4..000000000000 --- a/main/php_content_types.h +++ /dev/null @@ -1,18 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | Copyright © The PHP Group and Contributors. | - +----------------------------------------------------------------------+ - | This source file is subject to the Modified BSD License that is | - | bundled with this package in the file LICENSE, and is available | - | through the World Wide Web at . | - | | - | SPDX-License-Identifier: BSD-3-Clause | - +----------------------------------------------------------------------+ -*/ - -#ifndef PHP_CONTENT_TYPES_H -#define PHP_CONTENT_TYPES_H - -SAPI_API SAPI_POST_HANDLER_FUNC(php_std_post_handler); - -#endif /* PHP_CONTENT_TYPES_H */ diff --git a/main/php_variables.c b/main/php_variables.c index b510ea0b203c..398f6e484d28 100644 --- a/main/php_variables.c +++ b/main/php_variables.c @@ -20,7 +20,6 @@ #include "zend_smart_str.h" #include "php_variables.h" #include "php_globals.h" -#include "php_content_types.h" #include "SAPI.h" #include "zend_globals.h" #include "zend_exceptions.h" diff --git a/win32/build/config.w32 b/win32/build/config.w32 index a36c60dd348f..f5cca4f5b7bf 100644 --- a/win32/build/config.w32 +++ b/win32/build/config.w32 @@ -288,7 +288,7 @@ ADD_FLAG("CFLAGS_BD_ZEND", "/D ZEND_ENABLE_STATIC_TSRMLS_CACHE=1"); ADD_SOURCES("main", "main.c snprintf.c spprintf.c getopt.c flock_compat.c fopen_wrappers.c \ php_ini_builder.c php_glob.c \ - php_scandir.c php_ini.c SAPI.c rfc1867.c php_content_types.c strlcpy.c \ + php_scandir.c php_ini.c SAPI.c rfc1867.c strlcpy.c \ strlcat.c reentrancy.c php_variables.c php_ticks.c network.c \ php_open_temporary_file.c output.c internal_functions.c \ php_syslog.c php_odbc_utils.c safe_bcmp.c"); From 046786d4b41b82ddb94b58f7bd4ed62358931739 Mon Sep 17 00:00:00 2001 From: Calvin Buckley Date: Fri, 27 Nov 2026 12:02:52 -0400 Subject: [PATCH 6/7] sapi: move php_std_post_handler per Gina --- main/SAPI.h | 1 - main/php_variables.h | 2 ++ 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/main/SAPI.h b/main/SAPI.h index 9c81c2fc25f8..724cc4e7b325 100644 --- a/main/SAPI.h +++ b/main/SAPI.h @@ -310,7 +310,6 @@ END_EXTERN_C() #define DEFAULT_POST_CONTENT_TYPE "application/x-www-form-urlencoded" BEGIN_EXTERN_C() -SAPI_API SAPI_POST_HANDLER_FUNC(php_std_post_handler); SAPI_API SAPI_POST_READER_FUNC(sapi_read_standard_form_data); SAPI_API SAPI_TREAT_DATA_FUNC(php_default_treat_data); SAPI_API SAPI_INPUT_FILTER_FUNC(php_default_input_filter); diff --git a/main/php_variables.h b/main/php_variables.h index 27a45e8daa3c..174c131443f2 100644 --- a/main/php_variables.h +++ b/main/php_variables.h @@ -36,6 +36,8 @@ PHPAPI void php_register_variable_safe(const char *var, const char *val, size_t PHPAPI void php_register_variable_ex(const char *var, zval *val, zval *track_vars_array); PHPAPI void php_register_known_variable(const char *var, size_t var_len, zval *value, zval *track_vars_array); +SAPI_API SAPI_POST_HANDLER_FUNC(php_std_post_handler); + PHPAPI void php_build_argv(const char *s, zval *track_vars_array); PHPAPI zend_result php_hash_environment(void); END_EXTERN_C() From 58bc895fbe7c0675e0d2bda4a83690310376182f Mon Sep 17 00:00:00 2001 From: Calvin Buckley Date: Fri, 27 Nov 2026 14:21:49 -0400 Subject: [PATCH 7/7] sapi: POST handler/reader entries in NEWS --- UPGRADING.INTERNALS | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/UPGRADING.INTERNALS b/UPGRADING.INTERNALS index 3ad42019b585..792daccd7711 100644 --- a/UPGRADING.INTERNALS +++ b/UPGRADING.INTERNALS @@ -66,6 +66,10 @@ PHP 8.7 INTERNALS UPGRADE NOTES . The sapi_get_target_uid() function was removed. . The sapi_get_target_gid() function was removed. . The sapi_activate_headers_only() function was removed. + . The sapi_register_default_post_reader() function was removed. The default + POST reader indirection was vestigial. Register POST entries instead. + . The php_startup_sapi_content_types() function was removed. + . The php_setup_sapi_content_types() function was removed. . Removed zend_hrtime_posix_clock_id. zend_hrtime() always uses CLOCK_MONOTONIC on POSIX platforms. . The INIT_CLASS_ENTRY_INIT_METHODS() macro, which was previously used as @@ -100,6 +104,9 @@ PHP 8.7 INTERNALS UPGRADE NOTES . ZEND_IN_RANGE_OF(x, T) was added to check whether the value of an integer x is representable in the integer type T. . ZEND_TYPE_MIN(T) and ZEND_TYPE_MAX(T) were added. + . php_post_entries is now exposed as a symbol. Anything replacing POST + handlers should use this when switching back to PHP's defaults, rather + than having a copy of it. - Deprecated: . ZEND_LONG_INT_OVFL(), ZEND_LONG_INT_UDFL(), ZEND_LONG_EXCEEDS_INT(), @@ -166,6 +173,7 @@ PHP 8.7 INTERNALS UPGRADE NOTES . The force_http_10 method has been removed. . The get_fd method has been removed. . The get_target_uid and get_target_gid methods have been removed. + . The default_post_reader method has been removed. - Per-thread TSRM resources are now released best-effort at normal thread exit, because native TLS resource destructors can only run on their owning thread and