Skip to content

Commit 5dcb8f2

Browse files
committed
Fix #72941: Modifying bucket->data by-ref has no effect any longer
To match the PHP 5 behavior, we have to explicitly cater to `buffer` or `data` being references. Closes GH-6096.
1 parent 07cb665 commit 5dcb8f2

File tree

3 files changed

+39
-2
lines changed

3 files changed

+39
-2
lines changed

NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ PHP NEWS
2626
- Standard:
2727
. Fixed bug #79986 (str_ireplace bug with diacritics characters). (cmb)
2828
. Fixed bug #80077 (getmxrr test bug). (Rainer Jung)
29+
. Fixed bug #72941 (Modifying bucket->data by-ref has no effect any longer).
30+
(cmb)
2931

3032
03 Sep 2020, PHP 7.3.22
3133

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
--TEST--
2+
Bug #72941 (Modifying bucket->data by-ref has no effect any longer)
3+
--FILE--
4+
<?php
5+
class rotate_filter_nw extends php_user_filter
6+
{
7+
function filter($in, $out, &$consumed, $closing)
8+
{
9+
while ($bucket = stream_bucket_make_writeable($in)) {
10+
$this->rotate($bucket->data);
11+
$consumed += $bucket->datalen;
12+
stream_bucket_prepend($out, $bucket);
13+
}
14+
15+
return PSFS_PASS_ON;
16+
}
17+
18+
function rotate(&$data)
19+
{
20+
$n = strlen($data);
21+
for ($i = 0; $i < $n - 1; ++$i) {
22+
$data[$i] = $data[$i + 1];
23+
}
24+
}
25+
}
26+
27+
stream_filter_register("rotator_notWorking", rotate_filter_nw::class);
28+
$stream = fopen('php://memory', 'w+');
29+
fwrite($stream, 'hello, world');
30+
rewind($stream);
31+
stream_filter_append($stream, "rotator_notWorking");
32+
var_dump(stream_get_contents($stream));
33+
?>
34+
--EXPECT--
35+
string(12) "ello, worldd"

ext/standard/user_filters.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -434,7 +434,7 @@ static void php_stream_bucket_attach(int append, INTERNAL_FUNCTION_PARAMETERS)
434434
Z_PARAM_OBJECT(zobject)
435435
ZEND_PARSE_PARAMETERS_END_EX(RETURN_FALSE);
436436

437-
if (NULL == (pzbucket = zend_hash_str_find(Z_OBJPROP_P(zobject), "bucket", sizeof("bucket")-1))) {
437+
if (NULL == (pzbucket = zend_hash_str_find_deref(Z_OBJPROP_P(zobject), "bucket", sizeof("bucket")-1))) {
438438
php_error_docref(NULL, E_WARNING, "Object has no bucket property");
439439
RETURN_FALSE;
440440
}
@@ -448,7 +448,7 @@ static void php_stream_bucket_attach(int append, INTERNAL_FUNCTION_PARAMETERS)
448448
RETURN_FALSE;
449449
}
450450

451-
if (NULL != (pzdata = zend_hash_str_find(Z_OBJPROP_P(zobject), "data", sizeof("data")-1)) && Z_TYPE_P(pzdata) == IS_STRING) {
451+
if (NULL != (pzdata = zend_hash_str_find_deref(Z_OBJPROP_P(zobject), "data", sizeof("data")-1)) && Z_TYPE_P(pzdata) == IS_STRING) {
452452
if (!bucket->own_buf) {
453453
bucket = php_stream_bucket_make_writeable(bucket);
454454
}

0 commit comments

Comments
 (0)