Bug #68743 [NEW]: Infinite loop when CURLOPT_INFILESIZE doesn't match sended data
| From: | sjaillet at gmail dot com | Date: | Sun, 04 Jan 2015 14:25:17 +0000 |
| Subject: | Bug #68743 [NEW]: Infinite loop when CURLOPT_INFILESIZE doesn't match sended data | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-189644@lists.php.net to get a copy of this message | ||
From: sjaillet at gmail dot com
Operating system: Ubuntu 14.04.1
PHP version: 5.6.4
Package: cURL related
Bug Type: Bug
Bug description:Infinite loop when CURLOPT_INFILESIZE doesn't match sended data
Description:
------------
cURL multi enter into an infinite loop when CURLOPT_INFILESIZE doesn't
match the size of sended data.
In the test script below I intentionally set the CURLOPT_INFILESIZE to
the size of the sended data plus 1 byte.
In the documentation we can see that CURLOPT_READFUNCTION should return
an empty string to signal an EOF.
So it's what I done in the following script.
So since CURLOPT_READFUNCTION returned the EOF signal which indicates
that there's nothing to wait for, I expected cURL to bail out and
throwing an error (or at least timeout), but the test script run into an
infinite loop instead.
Test script:
---------------
$options = [
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_RETURNTRANSFER => false,
CURLOPT_HEADER => false,
CURLOPT_CUSTOMREQUEST => 'PUT',
CURLOPT_UPLOAD => true,
CURLOPT_URL => 'http://httpbin.org/put',
CURLOPT_CONNECTTIMEOUT => 1,
CURLOPT_HTTPHEADER => [
'Content-Type: text/plain; charset=UTF-8',
],
CURLOPT_READFUNCTION => function($handle, $fp, $length) {
static $data = 'HelloWorld';
$readed = $data;
$data = '';
echo "Length asked: '{$length}'\n";
echo "Readed: '{$readed}'\n";
return $readed;
},
CURLOPT_INFILESIZE => strlen('HelloWorld') + 1 // The extra
byte
];
$handle = curl_init();
curl_setopt_array($handle, $options);
$mh = curl_multi_init();
curl_multi_add_handle($mh, $handle);
$running = 0;
do {
if (curl_multi_select($mh) === -1) {
usleep(1000);
}
curl_multi_exec($mh, $running);
echo "Number of running request(s): '{$running}'\n";
} while ($running > 0);
Expected result:
----------------
# of running request(s): '1'
# of running request(s): '1'
# of running request(s): '1'
# of running request(s): '1'
# of running request(s): '1'
# of running request(s): '1'
# of running request(s): '1'
Length asked: '16384'
Readed: 'HelloWorld'
# of running request(s): '1'
Length asked: '16384'
Readed: ''
# of running request(s): '1'
# of running request(s): '0'
And a call to curl_strerror() should be able to display the error.
Actual result:
--------------
# of running request(s): '1'
# of running request(s): '1'
# of running request(s): '1'
# of running request(s): '1'
# of running request(s): '1'
# of running request(s): '1'
# of running request(s): '1'
Length asked: '16384'
Readed: 'HelloWorld'
# of running request(s): '1'
Length asked: '16384'
Readed: ''
# of running request(s): '1'
# of running request(s): '1'
# of running request(s): '1'
# of running request(s): '1'
# of running request(s): '1'
# of running request(s): '1'
# of running request(s): '1'
# of running request(s): '1'
# of running request(s): '1'
# of running request(s): '1'
# of running request(s): '1'
# of running request(s): '1'
# of running request(s): '1'
... etc.
--
Edit bug report at https://bugs.php.net/bug.php?id=68743&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=68743&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=68743&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=68743&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=68743&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=68743&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=68743&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=68743&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=68743&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=68743&r=support
Expected behavior: https://bugs.php.net/fix.php?id=68743&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=68743&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=68743&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=68743&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=68743&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=68743&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=68743&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=68743&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=68743&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=68743&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=68743&r=mysqlcfg