Bug #80518 [Com]: CURLOPT_READFUNCTION stream can't rewind
| From: | malacca42 at gmail dot com | Date: | Tue, 15 Dec 2020 10:37:15 +0000 |
| Subject: | Bug #80518 [Com]: CURLOPT_READFUNCTION stream can't rewind | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-231093@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=80518&edit=1
ID: 80518
Comment by: malacca42 at gmail dot com
Reported by: malacca42 at gmail dot com
Summary: CURLOPT_READFUNCTION stream can't rewind
Status: Open
Type: Bug
Package: cURL related
Operating System: windows
PHP Version: 8.0.0
Block user comment: N
Private report: N
New Comment:
replace CURLOPT_READFUNCTION to CURLOPT_INFILE still has same issue
Test script:
---------------
$file = __DIR__.'/payload';
$fp = fopen($file, 'r');
$ch = curl_init('http://localhost/server.php');
curl_setopt_array($ch, [
CURLOPT_VERBOSE => true,
CURLOPT_CUSTOMREQUEST => 'PUT',
CURLOPT_FOLLOWLOCATION => true, // follow location
CURLOPT_UPLOAD => true,
CURLOPT_INFILESIZE => filesize($file),
CURLOPT_INFILE => $fp,
]);
curl_exec($ch);
curl_close($ch);
result:
------------
also got "necessary data rewind wasn't possible"
Previous Comments:
------------------------------------------------------------------------
[2020-12-15 09:19:20] malacca42 at gmail dot com
Description:
------------
CURLOPT_READFUNCTION stream can't rewind
Test script:
---------------
$file = __DIR__.'/payload';
$fp = fopen($file, 'r');
$ch = curl_init('http://localhost/server.php');
curl_setopt_array($ch, [
CURLOPT_VERBOSE => true,
CURLOPT_CUSTOMREQUEST => 'PUT',
CURLOPT_FOLLOWLOCATION => true, // follow location
CURLOPT_UPLOAD => true,
CURLOPT_INFILESIZE => filesize($file),
CURLOPT_READFUNCTION => function ($ch, $fd, $length) use ($fp) {
return fread($fp, $length);
},
]);
curl_exec($ch);
curl_close($ch);
----------
the "server.php" is very simple
if (isset($_GET['n'])) {
echo file_get_contents('php://input');
} else {
Header("Location: sever.php?n=1");
http_response_code(307);
}
Expected result:
----------------
server can read payload after redirect
as RFC, entity body will resend after response 307 redirect
https://tools.ietf.org/html/rfc7231#section-6.4
but CURLOPT_READFUNCTION function only read once
maybe php lost CURLOPT_SEEKFUNCTION option
https://curl.se/libcurl/c/CURLOPT_SEEKFUNCTION.html
One more thing:
this is very very slow using php8, php7 is fast
Actual result:
--------------
got issue
"necessary data rewind wasn't possible"
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=80518&edit=1