Skip to content

Commit 2f9d86b

Browse files
committed
phar: Fix broken return value of fflush() for phar file entries
The flush functions always return EOF, even in the success path. The success path should return 0 to indicate success. Closes GH-20474.
1 parent 48b19a8 commit 2f9d86b

File tree

5 files changed

+29
-3
lines changed

5 files changed

+29
-3
lines changed

NEWS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ PHP NEWS
2121
- Phar:
2222
. Fixed bug GH-20442 (Phar does not respect case-insensitiveness of
2323
__halt_compiler() when reading stub). (ndossche, TimWolla)
24+
. Fix broken return value of fflush() for phar file entries. (ndossche)
2425

2526
- PHPDBG:
2627
. Fixed ZPP type violation in phpdbg_get_executable() and phpdbg_end_oplog().

ext/phar/phar.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3225,7 +3225,7 @@ int phar_flush(phar_archive_data *phar, char *user_stub, zend_long len, int conv
32253225
return EOF;
32263226
}
32273227

3228-
return EOF;
3228+
return 0;
32293229

32303230
cleanup:
32313231
if (shared_cfp != NULL) {

ext/phar/tar.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1378,6 +1378,6 @@ int phar_tar_flush(phar_archive_data *phar, char *user_stub, zend_long len, int
13781378
php_stream_close(newfile);
13791379
}
13801380
}
1381-
return EOF;
1381+
return 0;
13821382
}
13831383
/* }}} */
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
--TEST--
2+
fflush() on phar file should report success
3+
--EXTENSIONS--
4+
phar
5+
--INI--
6+
phar.readonly=0
7+
--FILE--
8+
<?php
9+
10+
$phar = new Phar(__DIR__.'/fflush_phar_file_report_success.phar');
11+
$phar->addFromString('test', 'contents');
12+
unset($phar);
13+
14+
$f = fopen('phar://' . __DIR__.'/fflush_phar_file_report_success.phar/test', 'w');
15+
var_dump(fflush($f));
16+
var_dump(fclose($f));
17+
18+
?>
19+
--CLEAN--
20+
<?php
21+
@unlink(__DIR__.'/fflush_phar_file_report_success.phar');
22+
?>
23+
--EXPECT--
24+
bool(true)
25+
bool(true)

ext/phar/zip.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1542,6 +1542,6 @@ int phar_zip_flush(phar_archive_data *phar, char *user_stub, zend_long len, int
15421542
if (closeoldfile) {
15431543
php_stream_close(oldfile);
15441544
}
1545-
return EOF;
1545+
return 0;
15461546
}
15471547
/* }}} */

0 commit comments

Comments
 (0)