diff --git a/ext/phar/stream.c b/ext/phar/stream.c index bfa826542d34..19ba48f87500 100644 --- a/ext/phar/stream.c +++ b/ext/phar/stream.c @@ -357,11 +357,11 @@ static php_stream * phar_wrapper_open_url(php_stream_wrapper *wrapper, const cha static int phar_stream_close(php_stream *stream, int close_handle) /* {{{ */ { /* for some reasons phar needs to be flushed even if there is no write going on */ - phar_stream_flush(stream); + int ret = phar_stream_flush(stream); phar_entry_delref((phar_entry_data *)stream->abstract); - return 0; + return ret; } /* }}} */ diff --git a/ext/phar/tests/gh21799-stream-close-flush.phpt b/ext/phar/tests/gh21799-stream-close-flush.phpt new file mode 100644 index 000000000000..aaa6c17fac38 --- /dev/null +++ b/ext/phar/tests/gh21799-stream-close-flush.phpt @@ -0,0 +1,32 @@ +--TEST-- +GH-21799: phar_stream_close propagates phar_stream_flush return value +--EXTENSIONS-- +phar +--INI-- +phar.readonly=0 +phar.require_hash=0 +--FILE-- +addFromString('hello.txt', 'hello'); +unset($phar); + +$fp = fopen('phar://' . $fname . '/hello.txt', 'rb'); +$content = fread($fp, 1024); +$result = fclose($fp); + +echo $content . "\n"; +var_dump($result); +echo "no crash\n"; +?> +--CLEAN-- + +--EXPECT-- +hello +bool(true) +no crash