Skip to content

Commit 9a9ad56

Browse files
committedNov 28, 2016
Fixed bug #73586 (php_user_filter::$stream is not set to the stream the filter is working on).
1 parent 970f21b commit 9a9ad56

File tree

4 files changed

+60
-1
lines changed

4 files changed

+60
-1
lines changed
 

‎NEWS

+4
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ PHP NEWS
99
- PCRE:
1010
. Fixed bug #73612 (preg_*() may leak memory). (cmb)
1111

12+
- Streams:
13+
. Fixed bug #73586 (php_user_filter::$stream is not set to the stream the
14+
filter is working on). (Dmitry)
15+
1216
08 Dec 2016 PHP 7.0.14
1317

1418
- Core:

‎Zend/zend_hash.h

+10
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,16 @@ static zend_always_inline zval *zend_hash_str_find_ind(const HashTable *ht, cons
301301
}
302302

303303

304+
static zend_always_inline int zend_hash_str_exists_ind(const HashTable *ht, const char *str, size_t len)
305+
{
306+
zval *zv;
307+
308+
zv = zend_hash_str_find(ht, str, len);
309+
return zv && (Z_TYPE_P(zv) != IS_INDIRECT ||
310+
Z_TYPE_P(Z_INDIRECT_P(zv)) != IS_UNDEF);
311+
}
312+
313+
304314
static zend_always_inline zval *zend_symtable_update(HashTable *ht, zend_string *key, zval *pData)
305315
{
306316
zend_ulong idx;
+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
--TEST--
2+
Bug #73586 (php_user_filter::$stream is not set to the stream the filter is working on).
3+
--FILE--
4+
<?php
5+
class append_filter extends php_user_filter {
6+
public $stream;
7+
function filter($in, $out, &$consumed, $closing) {
8+
while ($bucket = stream_bucket_make_writeable($in)) {
9+
$consumed += $bucket->datalen;
10+
stream_bucket_append($out, $bucket);
11+
}
12+
if ($closing) {
13+
$bucket = stream_bucket_new($this->stream, "FooBar\n");
14+
stream_bucket_append($out, $bucket);
15+
}
16+
return PSFS_PASS_ON;
17+
}
18+
}
19+
stream_filter_register("append", "append_filter");
20+
$fin = fopen(__FILE__, 'rb');
21+
stream_filter_append($fin, 'append', STREAM_FILTER_READ);
22+
stream_copy_to_stream($fin, STDOUT);
23+
?>
24+
--EXPECT--
25+
<?php
26+
class append_filter extends php_user_filter {
27+
public $stream;
28+
function filter($in, $out, &$consumed, $closing) {
29+
while ($bucket = stream_bucket_make_writeable($in)) {
30+
$consumed += $bucket->datalen;
31+
stream_bucket_append($out, $bucket);
32+
}
33+
if ($closing) {
34+
$bucket = stream_bucket_new($this->stream, "FooBar\n");
35+
stream_bucket_append($out, $bucket);
36+
}
37+
return PSFS_PASS_ON;
38+
}
39+
}
40+
stream_filter_register("append", "append_filter");
41+
$fin = fopen(__FILE__, 'rb');
42+
stream_filter_append($fin, 'append', STREAM_FILTER_READ);
43+
stream_copy_to_stream($fin, STDOUT);
44+
?>
45+
FooBar

‎ext/standard/user_filters.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ php_stream_filter_status_t userfilter_filter(
175175
return ret;
176176
}
177177

178-
if (!zend_hash_str_exists(Z_OBJPROP_P(obj), "stream", sizeof("stream")-1)) {
178+
if (!zend_hash_str_exists_ind(Z_OBJPROP_P(obj), "stream", sizeof("stream")-1)) {
179179
zval tmp;
180180

181181
/* Give the userfilter class a hook back to the stream */

1 commit comments

Comments
 (1)

KennedyTedesco commented on Aug 25, 2019

@KennedyTedesco
Contributor

@nikic @dstogov Is there any difference between these two approaches?

while ($bucket = stream_bucket_make_writeable($in)) {

And:

$bucket = \stream_bucket_make_writeable($in);

if ($bucket !== null) {
    // ...
}

Because every single test and use case I ever had, the while() wasn't touch more than once. Just exploring things here.

Thanks!

Please sign in to comment.