Bug #75315 [Com]: curl cutting off post data
| From: | j dot wessel at nolis dot de | Date: | Fri, 13 Oct 2017 10:24:03 +0000 |
| Subject: | Bug #75315 [Com]: curl cutting off post data | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-211668@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=75315&edit=1
ID: 75315
Comment by: j dot wessel at nolis dot de
Reported by: j dot wessel at nolis dot de
Summary: curl cutting off post data
Status: Open
Type: Bug
Package: cURL related
Operating System: Debian 9
PHP Version: 7.1.10
Block user comment: N
Private report: N
New Comment:
The change (https://github.com/curl/curl/commit/5f9e2ca09b57d82baf239039835b3b06dc41bbc5) fixes the
bug. The PHP example works perfekt after the change.
Previous Comments:
------------------------------------------------------------------------
[2017-10-07 15:23:47] lanched at gmail dot com
PHP 5.4.45 and curl 7.56.0
2 scripts:
1. test.php
----------------------------
<?php
//get the post and return it back
var_dump($_POST);
?>
------------------------------
2. test2.php
-------------------------------------------
<?php
$string="There is some random human-readable data number ";
$arr=[];
for($i=0;$i<1000;$i++) {
$arr[$i]=$string.$i;
};
$toSend=(['short_data_test'=>"123",'long_json'=>json_encode($arr),'something_else'=>'333222111']);
$curl= curl_init();
$options = [
CURLOPT_URL => "http://localhost/test.php",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => $toSend
];
curl_setopt_array($curl, $options);
$result=curl_exec($curl);
curl_close($curl);
echo"<pre>".PHP_EOL;
echo "we send:<br/>".PHP_EOL;
echo var_dump($toSend)."<br/>".PHP_EOL;
echo "<br/>";
echo "remote side got:<br/>".PHP_EOL;
echo $result."<br/>".PHP_EOL;
echo "<br/>";
echo "</pre>";
?>
--------------------------------------------------------------------------
now, execute taht script, and see:
(part of json)
"There is some random human-readable data number 300","There is some random
human-readable["There is some random human-readable data number 0"
and that repeats so and so on - every 16384 symbols of long sting (16k).
------------------------------------------------------------------------
[2017-10-05 12:37:51] j dot wessel at nolis dot de
We create a ticket at the curl project: https://github.com/curl/curl/issues/1949
------------------------------------------------------------------------
[2017-10-05 12:22:00] j dot wessel at nolis dot de
Description:
------------
Tested with: PHP 7.1.10, PHP 5.6.31 and curl 7.56.0
The script works with curl 7.55.0 correctly.
Test script:
---------------
curl.php
--------------------------------------------------------------------------------------
<?php
//generate string data
function getStr($num) {
$bstring = 'abcdefghijklmnopqrstuvxyz0123456789';
$str = '';
for($i = 0; $i < $num; $i++) {
$str .= $bstring;
}
return $str;
}
$json = [
'json1' => getStr(200),
'json2' => getStr(200),
'json3' => getStr(200),
'json4' => getStr(200),
];
$post = [
'test1' => 'a',
'test2' => 'b',
'test3' => 'c',
'test4' => json_encode($json) //or use print_r or var_dump with return parameter
];
$ch = curl_init();
//send encoded json-data to service
curl_setopt($ch, CURLOPT_URL, 'https://localhost/service.php');
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec ($ch);
curl_close($ch);
var_dump($result);
?>
service.php
--------------------------------------------------------------------------------------
<?php
//get the post data and write into request.log
$result = file_put_contents('request.log', print_r($_REQUEST, true));
var_dump($result);
//the content of $_REQUEST is wrong, json1 is repeated, content is cutted off
//expected result: correct content in $_REQUEST
?>
Expected result:
----------------
Correct post data in $_REQUEST.
Actual result:
--------------
the content of $_REQUEST is wrong, json1 is repeated, content is cutted off, the post data is
corrupt
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=75315&edit=1