Skip to content

Commit 30f3685

Browse files
iliaalGirgias
authored andcommitted
phar: propagate phar_stream_flush return value from phar_stream_close
phar_stream_close called phar_stream_flush but discarded its int return value, always returning 0 from the stream close operation. On a write- modified phar entry, a flush failure (e.g. disk full during archive commit) was silently ignored. Capture the flush result and return it so the stream layer gets an accurate close status. Closes GH-21799 Closes GH-21804
1 parent 0c99bd7 commit 30f3685

File tree

2 files changed

+34
-2
lines changed

2 files changed

+34
-2
lines changed

ext/phar/stream.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -357,11 +357,11 @@ static php_stream * phar_wrapper_open_url(php_stream_wrapper *wrapper, const cha
357357
static int phar_stream_close(php_stream *stream, int close_handle) /* {{{ */
358358
{
359359
/* for some reasons phar needs to be flushed even if there is no write going on */
360-
phar_stream_flush(stream);
360+
int ret = phar_stream_flush(stream);
361361

362362
phar_entry_delref((phar_entry_data *)stream->abstract);
363363

364-
return 0;
364+
return ret;
365365
}
366366
/* }}} */
367367

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
--TEST--
2+
GH-21799: phar_stream_close propagates phar_stream_flush return value
3+
--EXTENSIONS--
4+
phar
5+
--INI--
6+
phar.readonly=0
7+
phar.require_hash=0
8+
--FILE--
9+
<?php
10+
// Regression baseline: fclose() on a phar file handle succeeds on the
11+
// normal code path. phar_stream_close now returns the phar_stream_flush
12+
// result instead of always returning 0.
13+
$fname = __DIR__ . '/' . basename(__FILE__, '.php') . '.phar';
14+
15+
$phar = new Phar($fname);
16+
$phar->addFromString('hello.txt', 'hello');
17+
unset($phar);
18+
19+
$fp = fopen('phar://' . $fname . '/hello.txt', 'rb');
20+
$content = fread($fp, 1024);
21+
$result = fclose($fp);
22+
23+
echo $content . "\n";
24+
var_dump($result);
25+
echo "no crash\n";
26+
?>
27+
--CLEAN--
28+
<?php @unlink(__DIR__ . '/' . basename(__FILE__, '.clean.php') . '.phar'); ?>
29+
--EXPECT--
30+
hello
31+
bool(true)
32+
no crash

0 commit comments

Comments
 (0)