Skip to content

Commit fc5e737

Browse files
committed
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.
1 parent 19cb9c7 commit fc5e737

File tree

2 files changed

+45
-5
lines changed

2 files changed

+45
-5
lines changed

ext/soap/php_http.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1258,13 +1258,13 @@ int make_http_soap_request(zval *this_ptr,
12581258

12591259
if ((strcmp(content_encoding,"gzip") == 0 ||
12601260
strcmp(content_encoding,"x-gzip") == 0) &&
1261-
zend_hash_str_exists(EG(function_table), "gzinflate", sizeof("gzinflate")-1)) {
1262-
ZVAL_STRING(&func, "gzinflate");
1263-
ZVAL_STRINGL(&params[0], http_body->val+10, http_body->len-10);
1264-
} else if (strcmp(content_encoding,"deflate") == 0 &&
1265-
zend_hash_str_exists(EG(function_table), "gzuncompress", sizeof("gzuncompress")-1)) {
1261+
zend_hash_str_exists(EG(function_table), "gzuncompress", sizeof("gzuncompress")-1)) {
12661262
ZVAL_STRING(&func, "gzuncompress");
12671263
ZVAL_STR_COPY(&params[0], http_body);
1264+
} else if (strcmp(content_encoding,"deflate") == 0 &&
1265+
zend_hash_str_exists(EG(function_table), "gzinflate", sizeof("gzinflate")-1)) {
1266+
ZVAL_STRING(&func, "gzinflate");
1267+
ZVAL_STR_COPY(&params[0], http_body);
12681268
} else {
12691269
efree(content_encoding);
12701270
zend_string_release_ex(http_headers, 0);

ext/soap/tests/bugs/bug47925.phpt

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
--TEST--
2+
Bug #47925 (PHPClient can't decompress response (transposed uncompress methods?))
3+
--EXTENSIONS--
4+
soap
5+
zlib
6+
--SKIPIF--
7+
<?php
8+
if (@!include __DIR__."/../../../standard/tests/http/server.inc") die('skip server.inc not available');
9+
http_server_skipif();
10+
?>
11+
--FILE--
12+
<?php
13+
require __DIR__."/../../../standard/tests/http/server.inc";
14+
15+
$plain_response = <<<XML
16+
<?xml version="1.0" encoding="UTF-8"?>
17+
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://testuri.org" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
18+
<SOAP-ENV:Body>
19+
<ns1:AddResponse>
20+
<return xsi:type="xsd:int">7</return>
21+
</ns1:AddResponse>
22+
</SOAP-ENV:Body>
23+
</SOAP-ENV:Envelope>
24+
XML;
25+
26+
function test($compressed_response, $compression_name) {
27+
$length = strlen($compressed_response);
28+
$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");
29+
['pid' => $pid, 'uri' => $uri] = http_server([$server_response]);
30+
$client = new SoapClient(NULL, ['location' => $uri, 'uri' => $uri]);
31+
var_dump($client->Add(3, 4));
32+
http_server_kill($pid);
33+
}
34+
35+
test(gzcompress($plain_response), "gzip");
36+
test(gzdeflate($plain_response), "deflate");
37+
?>
38+
--EXPECT--
39+
int(7)
40+
int(7)

0 commit comments

Comments
 (0)