Edit report at https://bugs.php.net/bug.php?id=72131&edit=1
ID: 72131
Updated by: mike@php.net
Reported by: andre at webkr dot de
Summary: Calling number_format(null) causes curl to not
decode chunks
Status: Feedback
Type: Bug
Package: Reproducible crash
Operating System: Linux
PHP Version: 5.5.35
Block user comment: N
Private report: N
New Comment:
I can hardly think of any relation, but I have another problem: I cannot locate this error message;
what version of libcurl are you using?
Previous Comments:
------------------------------------------------------------------------
[2016-04-30 05:50:39] andre at webkr dot de
Indeed the problem exists with number_format(0), too.
So that is:
number_format(null) -> problem
number_format(0) -> problem
number_format(1) -> no problem
// number_format(0) -> no problem
------------------------------------------------------------------------
[2016-04-30 05:34:44] pajoye@php.net
number_format(null); is the same than number_format(0); except if strict_types=1 is used. And
nothing in the number_format function affects something in the current context or globally.
(see http://lxr.php.net/xref/PHP_MASTER/ext/standard/math.c#1275)
Only to confirm the issue, the problem disappears if you remove the if ($i >= 2) block altogether
right?
------------------------------------------------------------------------
[2016-04-29 23:05:00] andre at webkr dot de
Here's a Dockerfile that reproduces the bug and a little server (in Go) that returns chunked
responses:
https://github.com/AndreKR/php-bug-72131
------------------------------------------------------------------------
[2016-04-29 22:46:14] andre at webkr dot de
Description:
------------
This bug exists in PHP 5.5.35, PHP 5.6.21 and PHP 7.0.6.
When you make repeated curl requests to a server that returns the answer chunked-encoded, those
requests start to fail with the error "Problem (2) in the Chunked-Encoded data" as soon as
you call number_format(null).
Admittedly number_format(null) makes no sense, but it throws no error either.
When you call number_format(null) a second time, cURL can decode chunks again, a third
time again brings the error, and so on.
Test script:
---------------
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://localhost/');
// This URL must return a chunked response
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
for($i = 0 ; $i < 10 ; $i++)
{
$result = curl_exec($ch);
var_dump($result);
var_dump(curl_error($ch));
if($i >= 2) {
echo "\n" . 'number_format(null) called' . "\n";
number_format(null);
}
echo "\n";
}
Expected result:
----------------
(Created by requesting a URL that does not respond in chunks)
string(2) "OK"
string(0) ""
string(2) "OK"
string(0) ""
string(2) "OK"
string(0) ""
number_format(null) called
string(2) "OK"
string(0) ""
number_format(null) called
string(2) "OK"
string(0) ""
number_format(null) called
string(2) "OK"
string(0) ""
number_format(null) called
string(2) "OK"
string(0) ""
number_format(null) called
string(2) "OK"
string(0) ""
number_format(null) called
string(2) "OK"
string(0) ""
number_format(null) called
string(2) "OK"
string(0) ""
number_format(null) called
Actual result:
--------------
string(2) "OK"
string(0) ""
string(2) "OK"
string(0) ""
string(2) "OK"
string(0) ""
number_format(null) called
bool(false)
string(39) "Problem (2) in the Chunked-Encoded data"
number_format(null) called
string(2) "OK"
string(0) ""
number_format(null) called
bool(false)
string(39) "Problem (2) in the Chunked-Encoded data"
number_format(null) called
string(2) "OK"
string(0) ""
number_format(null) called
bool(false)
string(39) "Problem (2) in the Chunked-Encoded data"
number_format(null) called
string(2) "OK"
string(0) ""
number_format(null) called
bool(false)
string(39) "Problem (2) in the Chunked-Encoded data"
number_format(null) called
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=72131&edit=1