Skip to content

Add missing checks for php_crc32_stream_bulk_update() in phar #18608

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: PHP-8.3
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion ext/phar/phar.c
Original file line number Diff line number Diff line change
Expand Up @@ -2799,7 +2799,16 @@ int phar_flush(phar_archive_data *phar, char *user_stub, zend_long len, int conv
return EOF;
}
newcrc32 = php_crc32_bulk_init();
php_crc32_stream_bulk_update(&newcrc32, file, entry->uncompressed_filesize);
if (php_crc32_stream_bulk_update(&newcrc32, file, entry->uncompressed_filesize) != SUCCESS) {
if (closeoldfile) {
php_stream_close(oldfile);
}
php_stream_close(newfile);
if (error) {
spprintf(error, 0, "unable to read file \"%s\" for crc32 while creating new phar \"%s\"", entry->filename, phar->fname);
}
return EOF;
}
entry->crc32 = php_crc32_bulk_end(newcrc32);
entry->is_crc_checked = 1;
if (!(entry->flags & PHAR_ENT_COMPRESSION_MASK)) {
Expand Down
5 changes: 4 additions & 1 deletion ext/phar/zip.c
Original file line number Diff line number Diff line change
Expand Up @@ -937,7 +937,10 @@ static int phar_zip_changed_apply_int(phar_entry_info *entry, void *arg) /* {{{
efp = phar_get_efp(entry, 0);
newcrc32 = php_crc32_bulk_init();

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

entry->crc32 = php_crc32_bulk_end(newcrc32);
PHAR_SET_32(central.uncompsize, entry->uncompressed_filesize);
Expand Down
Loading