php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #75315 curl cutting off post data
Submitted: 2017-10-05 12:22 UTC Modified: 2017-10-24 08:30 UTC
Votes:5
Avg. Score:3.8 ± 1.6
Reproduced:3 of 4 (75.0%)
Same Version:2 (66.7%)
Same OS:2 (66.7%)
From: j dot wessel at nolis dot de Assigned:
Status: Closed Package: cURL related
PHP Version: 7.1.10 OS: Debian 9
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: j dot wessel at nolis dot de
New email:
PHP Version: OS:

 

 [2017-10-05 12:22 UTC] 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

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2017-10-05 12:37 UTC] j dot wessel at nolis dot de
We create a ticket at the curl project: https://github.com/curl/curl/issues/1949
 [2017-10-07 15:23 UTC] 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-13 10:23 UTC] j dot wessel at nolis dot de
The change (https://github.com/curl/curl/commit/5f9e2ca09b57d82baf239039835b3b06dc41bbc5) fixes the bug. The PHP example works perfekt after the change.
 [2017-10-24 08:30 UTC] j dot wessel at nolis dot de
-Status: Open +Status: Closed
 [2017-10-24 08:30 UTC] j dot wessel at nolis dot de
The curl version 7.56.1 fixes the bug.
 [2018-01-05 10:09 UTC] peter at grootplezier dot nl
This problem still exists in the windows version of PHP.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Wed Feb 05 12:01:32 2025 UTC