Skip to content

Commit f7c43b8

Browse files
committed
Fix #47021: SoapClient stumbles over WSDL delivered with "Transfer-Encoding: chunked"
1 parent ff14b7a commit f7c43b8

File tree

3 files changed

+99
-2
lines changed

3 files changed

+99
-2
lines changed

NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ PHP NEWS
3838
. Fixed bug #64705 (errorInfo property of PDOException is null when
3939
PDO::__construct() fails). (Ahmed Abdou)
4040

41+
- SOAP:
42+
. Fixed bug #47021 (SoapClient stumbles over WSDL delivered with
43+
"Transfer-Encoding: chunked"). (Matteo)
44+
4145
- Standard:
4246
. Fixed bug #79930 (array_merge_recursive() crashes when called with array
4347
with single reference). (Nikita)

ext/soap/php_http.c

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1375,11 +1375,24 @@ static char *get_http_header_value(char *headers, char *type)
13751375

13761376
/* match */
13771377
tmp = pos + typelen;
1378+
1379+
/* strip leading whitespace */
1380+
while (*tmp == ' ' || *tmp == '\t') {
1381+
tmp++;
1382+
}
1383+
13781384
eol = strchr(tmp, '\n');
13791385
if (eol == NULL) {
13801386
eol = headers + headerslen;
1381-
} else if (eol > tmp && *(eol-1) == '\r') {
1382-
eol--;
1387+
} else if (eol > tmp) {
1388+
if (*(eol-1) == '\r') {
1389+
eol--;
1390+
}
1391+
1392+
/* strip trailing whitespace */
1393+
while (eol > tmp && (*(eol-1) == ' ' || *(eol-1) == '\t')) {
1394+
eol--;
1395+
}
13831396
}
13841397
return estrndup(tmp, eol - tmp);
13851398
}

ext/soap/tests/bug47021.phpt

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
--TEST--
2+
Bug #47021 SoapClient (SoapClient stumbles over WSDL delivered with "Transfer-Encoding: chunked")
3+
--INI--
4+
soap.wsdl_cache_enabled=0
5+
--SKIPIF--
6+
<?php
7+
8+
require 'skipif.inc';
9+
10+
require __DIR__.'/../../standard/tests/http/server.inc'; http_server_skipif('tcp://127.0.0.1:12342');
11+
12+
?>
13+
--FILE--
14+
<?php
15+
require __DIR__.'/../../standard/tests/http/server.inc';
16+
17+
function chunk_body($body, $n)
18+
{
19+
$chunks = str_split($body, $n);
20+
$chunks[] = '';
21+
22+
foreach ($chunks as $k => $v) {
23+
$chunks[$k] = sprintf("%08x\r\n%s\r\n", strlen($v), $v);
24+
}
25+
26+
return join('', $chunks);
27+
}
28+
29+
$wsdl = file_get_contents(__DIR__.'/server030.wsdl');
30+
31+
$soap = <<<EOF
32+
<?xml version="1.0" encoding="UTF-8"?>
33+
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://testuri.org" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" 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/"><SOAP-ENV:Body><ns1:getItemsResponse><getItemsReturn SOAP-ENC:arrayType="ns1:Item[10]" xsi:type="ns1:ItemArray"><item xsi:type="ns1:Item"><text xsi:type="xsd:string">text0</text></item><item xsi:type="ns1:Item"><text xsi:type="xsd:string">text1</text></item><item xsi:type="ns1:Item"><text xsi:type="xsd:string">text2</text></item><item xsi:type="ns1:Item"><text xsi:type="xsd:string">text3</text></item><item xsi:type="ns1:Item"><text xsi:type="xsd:string">text4</text></item><item xsi:type="ns1:Item"><text xsi:type="xsd:string">text5</text></item><item xsi:type="ns1:Item"><text xsi:type="xsd:string">text6</text></item><item xsi:type="ns1:Item"><text xsi:type="xsd:string">text7</text></item><item xsi:type="ns1:Item"><text xsi:type="xsd:string">text8</text></item><item xsi:type="ns1:Item"><text xsi:type="xsd:string">text9</text></item></getItemsReturn></ns1:getItemsResponse></SOAP-ENV:Body></SOAP-ENV:Envelope>
34+
EOF;
35+
36+
$responses = [
37+
"data://text/plain,HTTP/1.1 200 OK\r\n".
38+
"Content-Type: text/xml;charset=utf-8\r\n".
39+
"Transfer-Encoding: \t chunked\t \r\n".
40+
"Connection: close\r\n".
41+
"\r\n".
42+
chunk_body($wsdl, 64),
43+
"data://text/plain,HTTP/1.1 200 OK\r\n".
44+
"Content-Type: text/xml;charset=utf-8\r\n".
45+
"Transfer-Encoding: \t chunked\t \r\n".
46+
"Connection: close\r\n".
47+
"\r\n".
48+
chunk_body($soap, 156),
49+
];
50+
51+
52+
$pid = http_server('tcp://127.0.0.1:12342', $responses);
53+
54+
$options = [
55+
'trace' => true,
56+
'location' => 'http://127.0.0.1:12342/',
57+
];
58+
59+
class BugSoapClient extends SoapClient
60+
{
61+
public function __doRequest($request, $location, $action, $version, $one_way = null)
62+
{
63+
$response = parent::__doRequest($request, $location, $action, $version, $one_way);
64+
65+
var_dump(strlen($response));
66+
67+
return $response;
68+
}
69+
}
70+
71+
$client = new BugSoapClient('http://127.0.0.1:12342/', $options);
72+
73+
var_dump(count($client->getItems()));
74+
75+
http_server_kill($pid);
76+
77+
?>
78+
--EXPECT--
79+
int(1291)
80+
int(10)

0 commit comments

Comments
 (0)