Skip to content

Commit c56736f

Browse files
committed
Add missing checks for php_crc32_stream_bulk_update() in phar
1 parent 41e11a6 commit c56736f

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

ext/phar/phar.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2799,7 +2799,16 @@ int phar_flush(phar_archive_data *phar, char *user_stub, zend_long len, int conv
27992799
return EOF;
28002800
}
28012801
newcrc32 = php_crc32_bulk_init();
2802-
php_crc32_stream_bulk_update(&newcrc32, file, entry->uncompressed_filesize);
2802+
if (php_crc32_stream_bulk_update(&newcrc32, file, entry->uncompressed_filesize) != SUCCESS) {
2803+
if (closeoldfile) {
2804+
php_stream_close(oldfile);
2805+
}
2806+
php_stream_close(newfile);
2807+
if (error) {
2808+
spprintf(error, 0, "unable to read file \"%s\" for crc32 while creating new phar \"%s\"", entry->filename, phar->fname);
2809+
}
2810+
return EOF;
2811+
}
28032812
entry->crc32 = php_crc32_bulk_end(newcrc32);
28042813
entry->is_crc_checked = 1;
28052814
if (!(entry->flags & PHAR_ENT_COMPRESSION_MASK)) {

ext/phar/zip.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -937,7 +937,10 @@ static int phar_zip_changed_apply_int(phar_entry_info *entry, void *arg) /* {{{
937937
efp = phar_get_efp(entry, 0);
938938
newcrc32 = php_crc32_bulk_init();
939939

940-
php_crc32_stream_bulk_update(&newcrc32, efp, entry->uncompressed_filesize);
940+
if (php_crc32_stream_bulk_update(&newcrc32, efp, entry->uncompressed_filesize) != SUCCESS) {
941+
spprintf(p->error, 0, "unable to read file \"%s\" for crc32 in zip-based phar \"%s\"", entry->filename, entry->phar->fname);
942+
return ZEND_HASH_APPLY_STOP;
943+
}
941944

942945
entry->crc32 = php_crc32_bulk_end(newcrc32);
943946
PHAR_SET_32(central.uncompsize, entry->uncompressed_filesize);

0 commit comments

Comments
 (0)