Skip to content

Commit c2e5c58

Browse files
committed
Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3: Fix GH-17650: realloc with size 0 in user_filters.c
2 parents 0410369 + fd5d6ad commit c2e5c58

File tree

3 files changed

+39
-1
lines changed

3 files changed

+39
-1
lines changed

NEWS

+3
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ PHP NEWS
4343
. Partially fixed bug GH-17387 (Trivial crash in phpdbg lexer). (nielsdos)
4444
. Fix memory leak in phpdbg calling registered function. (nielsdos)
4545

46+
- Streams:
47+
. Fixed bug GH-17650 (realloc with size 0 in user_filters.c). (nielsdos)
48+
4649
30 Jan 2025, PHP 8.4.4
4750

4851
- Core:
+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
--TEST--
2+
GH-17650 (realloc with size 0 in user_filters.c)
3+
--FILE--
4+
<?php
5+
class testfilter extends php_user_filter {
6+
function filter($in, $out, &$consumed, $closing): int {
7+
while ($bucket = stream_bucket_make_writeable($in)) {
8+
$bucket->data = '';
9+
$consumed += strlen($bucket->data);
10+
stream_bucket_append($out, $bucket);
11+
}
12+
return PSFS_PASS_ON;
13+
}
14+
}
15+
16+
stream_filter_register('testfilter','testfilter');
17+
18+
$text = "Hello There!";
19+
20+
$fp = fopen('php://memory', 'w+');
21+
fwrite($fp, $text);
22+
23+
rewind($fp);
24+
stream_filter_append($fp, 'testfilter', STREAM_FILTER_READ, 'testuserfilter');
25+
26+
while ($x = fgets($fp)) {
27+
var_dump($x);
28+
}
29+
30+
fclose($fp);
31+
32+
echo "Done\n";
33+
?>
34+
--EXPECT--
35+
Done

ext/standard/user_filters.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,7 @@ static void php_stream_bucket_attach(int append, INTERNAL_FUNCTION_PARAMETERS)
402402
bucket = php_stream_bucket_make_writeable(bucket);
403403
}
404404
if (bucket->buflen != Z_STRLEN_P(pzdata)) {
405-
bucket->buf = perealloc(bucket->buf, Z_STRLEN_P(pzdata), bucket->is_persistent);
405+
bucket->buf = perealloc(bucket->buf, MAX(Z_STRLEN_P(pzdata), 1), bucket->is_persistent);
406406
bucket->buflen = Z_STRLEN_P(pzdata);
407407
}
408408
memcpy(bucket->buf, Z_STRVAL_P(pzdata), bucket->buflen);

0 commit comments

Comments
 (0)