XML-RPC chokes with long server response
clemens.tolboom - June 3, 2008 - 07:40
| Project: | Drupal |
| Version: | 7.x-dev |
| Component: | xml-rpc system |
| Category: | bug report |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | needs review |
Description
When receiving long responses from the server (my case 149 kB) preg_replace chokes in replacing the xml header.
Replacing this with a strpos() and substr() replacement I get my data parsed.
patch attached.
| Attachment | Size | Status | Test result | Operations |
|---|---|---|---|---|
| xmlrpc-choke.patch | 643 bytes | Idle | Failed: Failed to apply patch. | View details | Re-test |

#1
With chokes I mean it replaces the WHOLE message with an empty string. (Or was my data corrupt? afaik it was not)
My strpos searches for the first occurrence of '?>' while the preg_replace did an eager search for the last fitting '?>'
#2
Steps to reproduce.
1. With devel php block insert the following code
xmlrpc(); // lazy mans include$message = str_repeat( '<a>a</a>', 128); // 1K string
$message = str_repeat( $message, 80); // make n K in size
$message = '<e>'. $message .'</e>'; // wrap to make valid xml
$xml_message = xmlrpc_message( '<?xml version="1.0"?>'. $message); // create rpc message
xmlrpc_message_parse( $xml_message); // and parse
var_dump( $xml_message); // check for message value
2. Run the php
3. Note that message part is around 87K in size
4. Now change the 80 into 128
5. See the var_dump message containing a NULL value.
Is this memory dependant?
#3
needs to go into D7 first.
#4
Does apply to D5 and D6 but needs work for D7.
#5
This solution looks a little crude to me. What if there is a "?>" in the message but no XML header?
#6
Thinking about it, do we really need to strip the <?xml ?> tag.
I also noticed that the parser don't handle correctly the case when
$xmlrpc_message->messagetypeis not set at the end of the parsing (like in the case of a malformed message like the one above).#7
I wrote a test for this in #307477: xmlrpc test for big messages..
To run short I cannot reproduce with memory setting 64M.
Lowering to 32M same.
Lowering to 16M makes the whole testsuite die.
So I guess my test is wrong :(
#8
I rewrote the test. And it runs ok.
So my guess is this bug is a 'cannot reproduce' unless my test is wrong.
Patch #6 should be investigated. Although I prefer a test for it first.
#9
On third thought ... this is probably PHP version dependent.
My previous PHP version was a Ubuntu 7.04 version on which I reported this issue. I'm not sure how to get this version number :-( On http://packages.ubuntu.com/ choosing Feisty ginve PHP version 5.2.1
My current PHP version is PHP 5.2.4-2ubuntu5.3
So if someone has this older version of PHP he can run the new test #307477: xmlrpc test for big messages..
#10
The last submitted patch failed testing.
#11
In my case the xmlrpc message is about 500K the php is 5.2.9 and the problem is preg_replace().
I have fix the problem in this way.
#12
Moving to new 'xml-rpc system' component.
#13
#529608: xmlrpc_message_parse() in xmlrpc.inc is not safe for big XML-RPC responses marked as a duplicate.
Here is a reroll of my patch from #6.