From 35e62e9b590690f24fe78e3097d5bddcfb913e61 Mon Sep 17 00:00:00 2001 From: Niels Dossche <7771979+nielsdos@users.noreply.github.com> Date: Sat, 25 May 2024 16:11:43 +0200 Subject: [PATCH] Fix bug #47925: PHPClient can't decompress response (transposed uncompress methods?) The incorrect functions are being called to deal with incoming compressed data. gzip/x-gzip corresponds to gzuncompress(), while deflate corresponds to gzinflate(). The existing code for gzip compression also plays with removing the first 10 bytes (i.e. the gzip header) to pass it to the inflate implementation but that doesn't always work properly due to trailer data. Get rid of that entirely by using the correct functions. Closes GH-14321. --- NEWS | 3 +++ ext/soap/php_http.c | 10 ++++---- ext/soap/tests/bugs/bug47925.phpt | 40 +++++++++++++++++++++++++++++++ 3 files changed, 48 insertions(+), 5 deletions(-) create mode 100644 ext/soap/tests/bugs/bug47925.phpt diff --git a/NEWS b/NEWS index 6cec84d3df6..c23dfa700e6 100644 --- a/NEWS +++ b/NEWS @@ -12,6 +12,9 @@ PHP NEWS . Fixed bug GH-14267 (opcache.jit=off does not allow enabling JIT at runtime). (ilutov) +- Soap: + . Fixed bug #47925 (PHPClient can't decompress response). (nielsdos) + - Sodium: . Fix memory leaks in ext/sodium on failure of some functions. (nielsdos) diff --git a/ext/soap/php_http.c b/ext/soap/php_http.c index 5a887bd1e1e..f60f8b21caa 100644 --- a/ext/soap/php_http.c +++ b/ext/soap/php_http.c @@ -1258,13 +1258,13 @@ try_again: if ((strcmp(content_encoding,"gzip") == 0 || strcmp(content_encoding,"x-gzip") == 0) && - zend_hash_str_exists(EG(function_table), "gzinflate", sizeof("gzinflate")-1)) { - ZVAL_STRING(&func, "gzinflate"); - ZVAL_STRINGL(¶ms[0], http_body->val+10, http_body->len-10); - } else if (strcmp(content_encoding,"deflate") == 0 && - zend_hash_str_exists(EG(function_table), "gzuncompress", sizeof("gzuncompress")-1)) { + zend_hash_str_exists(EG(function_table), "gzuncompress", sizeof("gzuncompress")-1)) { ZVAL_STRING(&func, "gzuncompress"); ZVAL_STR_COPY(¶ms[0], http_body); + } else if (strcmp(content_encoding,"deflate") == 0 && + zend_hash_str_exists(EG(function_table), "gzinflate", sizeof("gzinflate")-1)) { + ZVAL_STRING(&func, "gzinflate"); + ZVAL_STR_COPY(¶ms[0], http_body); } else { efree(content_encoding); zend_string_release_ex(http_headers, 0); diff --git a/ext/soap/tests/bugs/bug47925.phpt b/ext/soap/tests/bugs/bug47925.phpt new file mode 100644 index 00000000000..ce14c7f4676 --- /dev/null +++ b/ext/soap/tests/bugs/bug47925.phpt @@ -0,0 +1,40 @@ +--TEST-- +Bug #47925 (PHPClient can't decompress response (transposed uncompress methods?)) +--EXTENSIONS-- +soap +zlib +--SKIPIF-- + +--FILE-- + + + + + 7 + + + +XML; + +function test($compressed_response, $compression_name) { + $length = strlen($compressed_response); + $server_response = "data://text/xml;base64," . base64_encode("HTTP/1.1 200 OK\r\nConnection: close\r\nContent-Encoding: $compression_name\r\nContent-Length: $length\r\n\r\n$compressed_response"); + ['pid' => $pid, 'uri' => $uri] = http_server([$server_response]); + $client = new SoapClient(NULL, ['location' => $uri, 'uri' => $uri]); + var_dump($client->Add(3, 4)); + http_server_kill($pid); +} + +test(gzcompress($plain_response), "gzip"); +test(gzdeflate($plain_response), "deflate"); +?> +--EXPECT-- +int(7) +int(7)