MantisBT - TestLink
View Issue Details
0008551TestLinkAPI - XMLRPCpublic2019-01-29 16:592020-02-09 12:14
1.9.17 (2018 Q1) 
0008551: Can't upload an execution attachment bigger than 400Ko
Similar to bug id 0005055

When uploading a large file (>400Ko) with a test case result using XML-RPC, an exception occurs :

br.eti.kinoshita.testlinkjavaapi.util.TestLinkAPIException: Error uploading attachment for execution: parse error. not well formed
Upload a 4Mo file via XML-RPC
I've patch it in class-IXR.php, same problem as report in bug id 0005055.
Not sure it's the best (not even a good) way to correct it.

function parse() {
        // Goal of this is to avoid too long lines for first line
        $this->message = str_replace("><",">\n<",$this->message);
        // first remove the XML declaration
        $this->message = preg_replace('/<\?xml(.*)?\?'.'>/', '', $this->message,1);

        if (trim($this->message) == '') {
            return false;
No tags attached.
Issue History
2019-01-29 16:59Mat83New Issue
2019-01-29 17:01Mat83Note Added: 0028476
2019-01-30 09:37fmanNote Added: 0028480
2019-01-30 13:55Mat83Note Added: 0028485
2019-01-31 09:03fmanNote Added: 0028487
2019-02-01 11:00Mat83Note Added: 0028491
2019-10-01 12:50jburgersNote Added: 0029232
2020-01-07 12:26hejuNote Added: 0029395
2020-01-07 12:26hejuNote Edited: 0029395bug_revision_view_page.php?bugnote_id=29395#r5985
2020-02-09 12:14jburgersNote Added: 0029470

2019-01-29 17:01   

was only for debug :)
2019-01-30 09:37   
In addition to the code, some comment explaining how this has been fixed is a must.
2019-01-30 13:55   
searching on the net I found the bug id 0005055 with same error,
then I checked that the error occurs at same place, when trying to remove the XML declaration. So I dump the message with :
The message is only on 1 ligne, and seems to be well formed.
I conclude the preg_replace can't manage a so long line, even with the bug id 5055 correction.
So I try to change the xml message with some \n between xml tag,
and no more error occurs.

hoping this answers the request, first time I post a bug on mantis ...
2019-01-31 09:03   
First or not first one reporting has no difference.
Please follow defacto standards for issue reporting
2019-02-01 11:00   
Some more information :
testlink installation is from bitnami docker 1.9.17 (PHP 7.1.23),
xml is generated from testlink-plugin (3.14) for jenkins (2.138.2)
2019-10-01 12:50   
Changing this line

$this->message = preg_replace('/<\?xml(.*)?\?'.'>/', '', $this->message,1);

for these two ones

$header = preg_replace('/<\?xml(.*)?\?'.'>/', '', substr($this->message, 0, 100),1);
$this->message = substr_replace($this->message, $header, 0, 100);

worked for me. I have tested with a 5MB attachment.

I have never worked before with PHP, so don't know if it is ok doing that.

(I took these guys work as reference: [^])
2020-01-07 12:26   
Hi @jburgers,

I noticed, that for slightly larger files than your test sample of 5MB, it fails again!

However in your linked file, there is already the fix:

Replace the whole function "function parse()", not only the first difference.

As this version has the additional improvement of parsing in chunks rather than the whole msg at once.

Tested with 109MB, upload works.

2020-02-09 12:14   
Hi @heju,

I'll do that, thanks!