php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #47021 SoapClient stumbles over WSDL delivered with "Transfer-Encoding: chunked"
Submitted: 2009-01-06 16:28 UTC Modified: 2009-04-16 10:56 UTC
Votes:53
Avg. Score:4.4 ± 0.8
Reproduced:50 of 50 (100.0%)
Same Version:30 (60.0%)
Same OS:30 (60.0%)
From: daniel dot gorski at develnet dot org Assigned:
Status: Closed Package: SOAP related
PHP Version: 5.3CVS-2009-01-06 (CVS) OS: Linux
Private report: No CVE-ID: None
 [2009-01-06 16:28 UTC] daniel dot gorski at develnet dot org
Description:
------------
The \SoapClient (and probably the \SoapServer) stumble over WSDL files that are delivered via HTTP in chunks, carrying the HTTP response header "Transfer-Encoding: chunked".


Reproduce code:
---------------
$sc = \SoapClient('http://any.wsdl/that/is/delivered/in/chunks');

Expected result:
----------------
No error, intantiation and initialization of the \SoapClient object.

Actual result:
--------------
Fatal error: Uncaught SoapFault exception: [WSDL] SOAP-ERROR: Parsing WSDL: Couldn't load from [URL]: Start tag expected, '<' not found in [FILE]

Patches

Pull Requests

Pull requests:

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-01-22 15:35 UTC] ml at x-net dot be
I can confirm this bug. I tried avoiding the chunking in Apache by using mod_deflate, but the PHP SOAP client probably doesn't send an Accept-Encoding header with gzip in it.
 [2009-01-26 10:54 UTC] giovanni at giacobbi dot net
Please see related discussion:
http://marc.info/?t=123291993300002&r=1&w=2

See also bug report #43069 which actually caused this bug.
 [2009-04-16 10:34 UTC] dmitry@php.net
This bug has been fixed in CVS.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.
 
Thank you for the report, and for helping us make PHP better.


 [2009-04-16 10:56 UTC] bjori@php.net
This was fixed by introducing an 'dechunk' stream filter, see http://news.php.net/php.cvs/57042

 [2009-05-17 05:18 UTC] shadda at gmail dot com
I ran into this bug today myself, and after having compiled the latest snapshot as of 8:00pm CST 2009-05-16 I am still experiencing this error.
 [2010-03-03 12:26 UTC] pcdinh at gmail dot com
Have you tried to recompile PHP with --without-curlwrapper? I solved my case.
 [2010-08-17 19:14 UTC] n dot engyozov at taxundo dot com
I can confirm the problem is still present in my PHP version 5.3.3 even after recompiling with changes made by Dmitry and with disabled curlwrapper. The problem breaks wsdls from yahoo i google APIs.
 [2012-05-16 15:45 UTC] gbaudoin at gmail dot com
Workaround : Use a stream context specifying the protocol 1.0 of HTTP :

$opts = array('http' => array('protocol_version' => '1.0'));
$context = stream_context_create($opts);
$this->client = new SoapClient($wsdl, array('stream_context' => $context));
 [2016-03-10 17:07 UTC] rowan dot collins at gmail dot com
After much head-scratching, I found the bug in the auto-decoding, which is actually independent of the SOAP wrapping, and occurs here: http://lxr.php.net/xref/PHP_MASTER/ext/standard/http_fopen_wrapper.c#774

The check looks for the exact line "Transfer-Encoding: chunked", but the number of spaces after the colon is arbitrary; thus any implementation that returns "Transfer-Encoding:  chunked" will not activate the "dechunk" filter.

You can reproduce this by pointing at an offending server with any stream wrapped function and enabling HTTP/1.1 (which is the default for SOAPClient, but not elsewhere):

<?php
$http_1_1_ctx = stream_context_create(["http" => ["protocol_version" => "1.1", "header" => "Connection: Close"]]);
file_get_contents($url, false, $http_1_1_ctx);
var_dump($http_response_header);
 [2016-03-10 17:17 UTC] rowan dot collins at gmail dot com
To test using the built-in web server:

# create file header-test.php
<?php
$spaces = str_repeat(' ', $_GET['s']);
header("Transfer-Encoding:{$spaces}Chunked");
echo "5\nHello\n0\n";

# Run server
php -S localhost:8080 header-test.php &

# Compare output with 1 vs 2 spaces

$http_1_1_ctx = stream_context_create(["http" => ["protocol_version" => "1.1", "header" => "Connection: Close"]]);
// Reports 'Hello', hides Transfer-Encoding header:
file_get_contents('http://localhost:8080/?s=1', false, $http_1_1_ctx);
var_dump($http_response_header);
// Reports raw chunk data, shows Transfer-Encoding header:
file_get_contents('http://localhost:8080/?s=2', false, $http_1_1_ctx);
var_dump($http_response_header);
 [2016-05-09 21:06 UTC] rowan dot collins at gmail dot com
I have submitted a Pull Request to make this detection handle any number of spaces in the HTTP header: https://github.com/php/php-src/pull/1902

Hopefully this will fix remaining instances of this bug.
 [2020-08-18 16:36 UTC] mbeccati@php.net
Automatic comment on behalf of mbeccati
Revision: http://git.php.net/?p=php-src.git;a=commit;h=f7c43b8c72822a4722bd7404c6f65e15b2b912c1
Log: Fix #47021: SoapClient stumbles over WSDL delivered with &quot;Transfer-Encoding: chunked&quot;
 [2020-08-18 16:36 UTC] mbeccati@php.net
-Status: Open +Status: Closed
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 12:01:31 2024 UTC