Skip to content

Commit 59c645b

Browse files
committed
Merge branch 'PHP-7.4' into master
* PHP-7.4: Fix #72941: Modifying bucket->data by-ref has no effect any longer
2 parents e1c422c + e6b2a97 commit 59c645b

File tree

2 files changed

+37
-2
lines changed

2 files changed

+37
-2
lines changed
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
@@ -425,7 +425,7 @@ static void php_stream_bucket_attach(int append, INTERNAL_FUNCTION_PARAMETERS)
425425
Z_PARAM_OBJECT(zobject)
426426
ZEND_PARSE_PARAMETERS_END();
427427

428-
if (NULL == (pzbucket = zend_hash_str_find(Z_OBJPROP_P(zobject), "bucket", sizeof("bucket")-1))) {
428+
if (NULL == (pzbucket = zend_hash_str_find_deref(Z_OBJPROP_P(zobject), "bucket", sizeof("bucket")-1))) {
429429
zend_argument_value_error(2, "must be an object that has a \"bucket\" property");
430430
RETURN_THROWS();
431431
}
@@ -439,7 +439,7 @@ static void php_stream_bucket_attach(int append, INTERNAL_FUNCTION_PARAMETERS)
439439
RETURN_THROWS();
440440
}
441441

442-
if (NULL != (pzdata = zend_hash_str_find(Z_OBJPROP_P(zobject), "data", sizeof("data")-1)) && Z_TYPE_P(pzdata) == IS_STRING) {
442+
if (NULL != (pzdata = zend_hash_str_find_deref(Z_OBJPROP_P(zobject), "data", sizeof("data")-1)) && Z_TYPE_P(pzdata) == IS_STRING) {
443443
if (!bucket->own_buf) {
444444
bucket = php_stream_bucket_make_writeable(bucket);
445445
}

0 commit comments

Comments
 (0)