Skip to content

Commit 91db3a1

Browse files
adoyGirgias
authored andcommitted
Fixed bug GH-10270 Unable to return CURL_READFUNC_PAUSE in readfunc callback
Closes GH-10607 Signed-off-by: George Peter Banyard <girgias@php.net>
1 parent 5f357f3 commit 91db3a1

File tree

4 files changed

+54
-0
lines changed

4 files changed

+54
-0
lines changed

NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ PHP NEWS
1515

1616
- Curl:
1717
. Fixed deprecation warning at compile time. (Max Kellermann)
18+
. Fixed bug GH-10270 (Unable to return CURL_READFUNC_PAUSE in readfunc
19+
callback). (Pierrick Charron)
1820

1921
- Date:
2022
. Fix GH-10447 ('p' format specifier does not yield 'Z' for 00:00). (Derick)

ext/curl/interface.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1547,6 +1547,8 @@ static size_t curl_read(char *data, size_t size, size_t nmemb, void *ctx)
15471547
if (Z_TYPE(retval) == IS_STRING) {
15481548
length = MIN((int) (size * nmemb), Z_STRLEN(retval));
15491549
memcpy(data, Z_STRVAL(retval), length);
1550+
} else if (Z_TYPE(retval) == IS_LONG) {
1551+
length = Z_LVAL_P(&retval);
15501552
}
15511553
zval_ptr_dtor(&retval);
15521554
}

ext/curl/tests/curl_pause_001.phpt

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
--TEST--
2+
Test CURL_READFUNC_PAUSE and curl_pause()
3+
--EXTENSIONS--
4+
curl
5+
--FILE--
6+
<?php
7+
include 'server.inc';
8+
$host = curl_cli_server_start();
9+
10+
class Input {
11+
private static $RESPONSES = [
12+
'Foo bar ',
13+
CURL_READFUNC_PAUSE,
14+
'baz qux',
15+
null
16+
];
17+
private int $res = 0;
18+
public function __invoke($ch, $hReadHandle, $iMaxOut)
19+
{
20+
return self::$RESPONSES[$this->res++];
21+
}
22+
}
23+
24+
$inputHandle = fopen(__FILE__, 'r');
25+
26+
$ch = curl_init();
27+
curl_setopt($ch, CURLOPT_URL, "{$host}/get.inc?test=input");
28+
curl_setopt($ch, CURLOPT_UPLOAD, 1);
29+
curl_setopt($ch, CURLOPT_READFUNCTION, new Input);
30+
curl_setopt($ch, CURLOPT_INFILE, $inputHandle);
31+
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
32+
33+
$mh = curl_multi_init();
34+
curl_multi_add_handle($mh, $ch);
35+
do {
36+
$status = curl_multi_exec($mh, $active);
37+
curl_pause($ch, CURLPAUSE_CONT);
38+
if ($active) {
39+
usleep(100);
40+
curl_multi_select($mh);
41+
}
42+
} while ($active && $status == CURLM_OK);
43+
44+
echo curl_multi_getcontent($ch);
45+
?>
46+
--EXPECT--
47+
string(15) "Foo bar baz qux"

ext/curl/tests/responder/get.inc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
case 'post':
55
var_dump($_POST);
66
break;
7+
case 'input':
8+
var_dump(file_get_contents('php://input'));
9+
break;
710
case 'getpost':
811
var_dump($_GET);
912
var_dump($_POST);

0 commit comments

Comments
 (0)