From 42eaf6bace906a383686dfac54a7fb3f83689044 Mon Sep 17 00:00:00 2001 From: Niels Dossche <7771979+nielsdos@users.noreply.github.com> Date: Wed, 2 Jul 2025 22:35:38 +0200 Subject: [PATCH 1/2] soap: Get decompression function directly from function table and call it The code is already looking up the entry in the function table anyway, so might as well use it directly. This simplifies the code and avoids a redundant lookup. --- ext/soap/php_http.c | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/ext/soap/php_http.c b/ext/soap/php_http.c index 69eca93268a8..088d6605b3cd 100644 --- a/ext/soap/php_http.c +++ b/ext/soap/php_http.c @@ -1294,20 +1294,18 @@ int make_http_soap_request(zval *this_ptr, /* Decompress response */ content_encoding = get_http_header_value(ZSTR_VAL(http_headers), "Content-Encoding:"); if (content_encoding) { - zval func; zval retval; zval params[1]; + zend_function *decompression_fn; /* Warning: the zlib function names are chosen in an unfortunate manner. * Check zlib.c to see how a function corresponds with a particular format. */ if ((strcmp(content_encoding,"gzip") == 0 || strcmp(content_encoding,"x-gzip") == 0) && - zend_hash_str_exists(EG(function_table), "gzdecode", sizeof("gzdecode")-1)) { - ZVAL_STRING(&func, "gzdecode"); + (decompression_fn = zend_hash_str_find_ptr(EG(function_table), "gzdecode", sizeof("gzdecode")-1))) { ZVAL_STR_COPY(¶ms[0], http_body); } else if (strcmp(content_encoding,"deflate") == 0 && - zend_hash_str_exists(EG(function_table), "gzuncompress", sizeof("gzuncompress")-1)) { - ZVAL_STRING(&func, "gzuncompress"); + (decompression_fn = zend_hash_str_find_ptr(EG(function_table), "gzuncompress", sizeof("gzuncompress")-1))) { ZVAL_STR_COPY(¶ms[0], http_body); } else { efree(content_encoding); @@ -1319,15 +1317,13 @@ int make_http_soap_request(zval *this_ptr, add_soap_fault(this_ptr, "HTTP", "Unknown Content-Encoding", NULL, NULL, SOAP_GLOBAL(lang_en)); return FALSE; } - if (call_user_function(CG(function_table), (zval*)NULL, &func, &retval, 1, params) == SUCCESS && - Z_TYPE(retval) == IS_STRING) { + zend_call_known_function(decompression_fn, NULL, NULL, &retval, 1, params, NULL); + if (Z_TYPE(retval) == IS_STRING) { zval_ptr_dtor(¶ms[0]); - zval_ptr_dtor(&func); zend_string_release_ex(http_body, 0); ZVAL_COPY_VALUE(return_value, &retval); } else { zval_ptr_dtor(¶ms[0]); - zval_ptr_dtor(&func); zval_ptr_dtor(&retval); efree(content_encoding); zend_string_release_ex(http_headers, 0); From c6114a1d382e09eb49450ff9c26331a6da8838fe Mon Sep 17 00:00:00 2001 From: Niels Dossche <7771979+nielsdos@users.noreply.github.com> Date: Wed, 2 Jul 2025 22:38:08 +0200 Subject: [PATCH 2/2] soap: Avoid redundant copying of http body string --- ext/soap/php_http.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/ext/soap/php_http.c b/ext/soap/php_http.c index 088d6605b3cd..c9a4e4843593 100644 --- a/ext/soap/php_http.c +++ b/ext/soap/php_http.c @@ -1303,10 +1303,10 @@ int make_http_soap_request(zval *this_ptr, if ((strcmp(content_encoding,"gzip") == 0 || strcmp(content_encoding,"x-gzip") == 0) && (decompression_fn = zend_hash_str_find_ptr(EG(function_table), "gzdecode", sizeof("gzdecode")-1))) { - ZVAL_STR_COPY(¶ms[0], http_body); + ZVAL_STR(¶ms[0], http_body); } else if (strcmp(content_encoding,"deflate") == 0 && (decompression_fn = zend_hash_str_find_ptr(EG(function_table), "gzuncompress", sizeof("gzuncompress")-1))) { - ZVAL_STR_COPY(¶ms[0], http_body); + ZVAL_STR(¶ms[0], http_body); } else { efree(content_encoding); zend_string_release_ex(http_headers, 0); @@ -1319,11 +1319,9 @@ int make_http_soap_request(zval *this_ptr, } zend_call_known_function(decompression_fn, NULL, NULL, &retval, 1, params, NULL); if (Z_TYPE(retval) == IS_STRING) { - zval_ptr_dtor(¶ms[0]); zend_string_release_ex(http_body, 0); ZVAL_COPY_VALUE(return_value, &retval); } else { - zval_ptr_dtor(¶ms[0]); zval_ptr_dtor(&retval); efree(content_encoding); zend_string_release_ex(http_headers, 0);