Skip to content

Commit 7809d51

Browse files
committed
Merge branch 'PHP-8.4' into PHP-8.5
* PHP-8.4: Revert "ext/phar: Voidify flush function as it always returns EOL" phar: Fix broken return value of fflush() for phar file entries
2 parents 7263cb6 + 08ec409 commit 7809d51

File tree

7 files changed

+93
-63
lines changed

7 files changed

+93
-63
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: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2504,16 +2504,16 @@ zend_string *phar_create_default_stub(const char *index_php, const char *web_ind
25042504
}
25052505
/* }}} */
25062506

2507-
void phar_flush(phar_archive_data *phar, char **error) {
2508-
phar_flush_ex(phar, NULL, false, error);
2507+
int phar_flush(phar_archive_data *phar, char **error) {
2508+
return phar_flush_ex(phar, NULL, false, error);
25092509
}
25102510

25112511
/**
25122512
* Save phar contents to disk
25132513
*
25142514
* if user_stub is NULL the default or existing stub should be used
25152515
*/
2516-
void phar_flush_ex(phar_archive_data *phar, zend_string *user_stub, bool is_default_stub, char **error) /* {{{ */
2516+
int phar_flush_ex(phar_archive_data *phar, zend_string *user_stub, bool is_default_stub, char **error) /* {{{ */
25172517
{
25182518
static const char halt_stub[] = "__HALT_COMPILER();";
25192519

@@ -2541,31 +2541,29 @@ void phar_flush_ex(phar_archive_data *phar, zend_string *user_stub, bool is_defa
25412541
if (error) {
25422542
spprintf(error, 0, "internal error: attempt to flush cached zip-based phar \"%s\"", phar->fname);
25432543
}
2544-
return;
2544+
return EOF;
25452545
}
25462546

25472547
if (error) {
25482548
*error = NULL;
25492549
}
25502550

25512551
if (!zend_hash_num_elements(&phar->manifest) && !user_stub) {
2552-
return;
2552+
return EOF;
25532553
}
25542554

25552555
zend_hash_clean(&phar->virtual_dirs);
25562556

25572557
if (phar->is_zip) {
2558-
phar_zip_flush(phar, user_stub, is_default_stub, error);
2559-
return;
2558+
return phar_zip_flush(phar, user_stub, is_default_stub, error);
25602559
}
25612560

25622561
if (phar->is_tar) {
2563-
phar_tar_flush(phar, user_stub, is_default_stub, error);
2564-
return;
2562+
return phar_tar_flush(phar, user_stub, is_default_stub, error);
25652563
}
25662564

25672565
if (PHAR_G(readonly)) {
2568-
return;
2566+
return EOF;
25692567
}
25702568

25712569
if (phar->fp && !phar->is_brandnew) {
@@ -2584,7 +2582,7 @@ void phar_flush_ex(phar_archive_data *phar, zend_string *user_stub, bool is_defa
25842582
if (must_close_old_file) {
25852583
php_stream_close(oldfile);
25862584
}
2587-
return;
2585+
return EOF;
25882586
}
25892587

25902588
if (user_stub) {
@@ -2598,7 +2596,7 @@ void phar_flush_ex(phar_archive_data *phar, zend_string *user_stub, bool is_defa
25982596
if (error) {
25992597
spprintf(error, 0, "illegal stub for phar \"%s\" (__HALT_COMPILER(); is missing)", phar->fname);
26002598
}
2601-
return;
2599+
return EOF;
26022600
}
26032601

26042602
size_t len = pos - ZSTR_VAL(user_stub) + strlen(halt_stub);
@@ -2616,7 +2614,7 @@ void phar_flush_ex(phar_archive_data *phar, zend_string *user_stub, bool is_defa
26162614
if (error) {
26172615
spprintf(error, 0, "unable to create stub from string in new phar \"%s\"", phar->fname);
26182616
}
2619-
return;
2617+
return EOF;
26202618
}
26212619
phar->halt_offset = len + end_sequence_len;
26222620
} else {
@@ -2646,7 +2644,7 @@ void phar_flush_ex(phar_archive_data *phar, zend_string *user_stub, bool is_defa
26462644
if (new_stub) {
26472645
zend_string_free(new_stub);
26482646
}
2649-
return;
2647+
return EOF;
26502648
}
26512649
if (new_stub) {
26522650
zend_string_free(new_stub);
@@ -2742,7 +2740,7 @@ void phar_flush_ex(phar_archive_data *phar, zend_string *user_stub, bool is_defa
27422740
if (error) {
27432741
spprintf(error, 0, "unable to seek to start of file \"%s\" while creating new phar \"%s\"", ZSTR_VAL(entry->filename), phar->fname);
27442742
}
2745-
return;
2743+
return EOF;
27462744
}
27472745
newcrc32 = php_crc32_bulk_init();
27482746
php_crc32_stream_bulk_update(&newcrc32, file, entry->uncompressed_filesize);
@@ -2768,7 +2766,7 @@ void phar_flush_ex(phar_archive_data *phar, zend_string *user_stub, bool is_defa
27682766
spprintf(error, 0, "unable to bzip2 compress file \"%s\" to new phar \"%s\"", ZSTR_VAL(entry->filename), phar->fname);
27692767
}
27702768
}
2771-
return;
2769+
return EOF;
27722770
}
27732771

27742772
/* create new file that holds the compressed versions */
@@ -3094,7 +3092,7 @@ void phar_flush_ex(phar_archive_data *phar, zend_string *user_stub, bool is_defa
30943092
php_stream_close(oldfile);
30953093
}
30963094
php_stream_close(newfile);
3097-
return;
3095+
return EOF;
30983096
}
30993097

31003098
php_stream_write(newfile, digest, digest_len);
@@ -3146,7 +3144,7 @@ void phar_flush_ex(phar_archive_data *phar, zend_string *user_stub, bool is_defa
31463144
if (error) {
31473145
spprintf(error, 4096, "unable to open new phar \"%s\" for writing", phar->fname);
31483146
}
3149-
return;
3147+
return EOF;
31503148
}
31513149

31523150
if (phar->flags & PHAR_FILE_COMPRESSED_GZ) {
@@ -3162,7 +3160,7 @@ void phar_flush_ex(phar_archive_data *phar, zend_string *user_stub, bool is_defa
31623160
if (error) {
31633161
spprintf(error, 4096, "unable to compress all contents of phar \"%s\" using zlib, PHP versions older than 5.2.6 have a buggy zlib", phar->fname);
31643162
}
3165-
return;
3163+
return EOF;
31663164
}
31673165

31683166
php_stream_filter_append(&phar->fp->writefilters, filter);
@@ -3192,9 +3190,10 @@ void phar_flush_ex(phar_archive_data *phar, zend_string *user_stub, bool is_defa
31923190
if (error) {
31933191
spprintf(error, 0, "unable to seek to __HALT_COMPILER(); in new phar \"%s\"", phar->fname);
31943192
}
3193+
return EOF;
31953194
}
31963195

3197-
return;
3196+
return 0;
31983197

31993198
cleanup:
32003199
if (shared_cfp != NULL) {
@@ -3206,6 +3205,8 @@ void phar_flush_ex(phar_archive_data *phar, zend_string *user_stub, bool is_defa
32063205
entry->header_offset = 0;
32073206
}
32083207
} ZEND_HASH_FOREACH_END();
3208+
3209+
return EOF;
32093210
}
32103211
/* }}} */
32113212

ext/phar/phar_internal.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -446,12 +446,12 @@ zend_result phar_copy_on_write(phar_archive_data **pphar);
446446
bool phar_is_tar(char *buf, char *fname);
447447
zend_result phar_parse_tarfile(php_stream* fp, char *fname, size_t fname_len, char *alias, size_t alias_len, phar_archive_data** pphar, uint32_t compression, char **error);
448448
zend_result phar_open_or_create_tar(char *fname, size_t fname_len, char *alias, size_t alias_len, int is_data, uint32_t options, phar_archive_data** pphar, char **error);
449-
void phar_tar_flush(phar_archive_data *phar, zend_string *user_stub, bool is_default_stub, char **error);
449+
int phar_tar_flush(phar_archive_data *phar, zend_string *user_stub, bool is_default_stub, char **error);
450450

451451
/* zip functions in zip.c */
452452
int phar_parse_zipfile(php_stream *fp, char *fname, size_t fname_len, char *alias, size_t alias_len, phar_archive_data** pphar, char **error);
453453
int phar_open_or_create_zip(char *fname, size_t fname_len, char *alias, size_t alias_len, int is_data, uint32_t options, phar_archive_data** pphar, char **error);
454-
void phar_zip_flush(phar_archive_data *archive, zend_string *user_stub, bool is_default_stub, char **error);
454+
int phar_zip_flush(phar_archive_data *archive, zend_string *user_stub, bool is_default_stub, char **error);
455455

456456
#ifdef PHAR_MAIN
457457
extern const php_stream_wrapper php_stream_phar_wrapper;
@@ -467,8 +467,8 @@ phar_entry_info *phar_get_entry_info(phar_archive_data *phar, char *path, size_t
467467
phar_entry_info *phar_get_entry_info_dir(phar_archive_data *phar, char *path, size_t path_len, char dir, char **error, int security);
468468
phar_entry_data *phar_get_or_create_entry_data(char *fname, size_t fname_len, char *path, size_t path_len, const char *mode, char allow_dir, char **error, int security);
469469
zend_result phar_get_entry_data(phar_entry_data **ret, char *fname, size_t fname_len, char *path, size_t path_len, const char *mode, char allow_dir, char **error, int security);
470-
void phar_flush_ex(phar_archive_data *archive, zend_string *user_stub, bool is_default_stub, char **error);
471-
void phar_flush(phar_archive_data *archive, char **error);
470+
int phar_flush_ex(phar_archive_data *archive, zend_string *user_stub, bool is_default_stub, char **error);
471+
int phar_flush(phar_archive_data *archive, char **error);
472472
zend_result phar_detect_phar_fname_ext(const char *filename, size_t filename_len, const char **ext_str, size_t *ext_len, int executable, int for_create, int is_complete);
473473
zend_result phar_split_fname(const char *filename, size_t filename_len, char **arch, size_t *arch_len, char **entry, size_t *entry_len, int executable, int for_create);
474474

ext/phar/stream.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -467,16 +467,17 @@ static ssize_t phar_stream_write(php_stream *stream, const char *buf, size_t cou
467467
static int phar_stream_flush(php_stream *stream) /* {{{ */
468468
{
469469
char *error;
470+
int ret;
470471
phar_entry_data *data = (phar_entry_data *) stream->abstract;
471472

472473
if (data->internal_file->is_modified) {
473474
data->internal_file->timestamp = time(0);
474-
phar_flush(data->phar, &error);
475+
ret = phar_flush(data->phar, &error);
475476
if (error) {
476477
php_stream_wrapper_log_error(stream->wrapper, REPORT_ERRORS, "%s", error);
477478
efree(error);
478479
}
479-
return EOF;
480+
return ret;
480481
} else {
481482
return EOF;
482483
}

0 commit comments

Comments
 (0)