Skip to content

Prevent double-free of Phar ZIP stream #6578

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

Closed
wants to merge 2 commits into from

Conversation

cmb69
Copy link
Member

@cmb69 cmb69 commented Jan 5, 2021

We must not alias the closed stream to phar_archive_data.fp.

We must not alias the closed stream to `phar_archive_data.fp`.
@cmb69 cmb69 changed the base branch from master to PHP-8.0 January 5, 2021 09:52
@@ -683,6 +681,8 @@ int phar_parse_zipfile(php_stream *fp, char *fname, size_t fname_len, char *alia
return FAILURE;
}

mydata->fp = fp;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like there's a bunch of usages above that use PHAR_ZIP_FAIL rather than phar_destroy_phar_data -- just want to double check whether using phar_destroy_phar_data is really okay here.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, right! At least for consistency, we should use the PHAR_ZIP_FAIL() macro. However, not calling phar_destroy_phar_data() keeps some memory allocated until request shutdown; that is handled differently in ext/phar/tar.c. Might be worthwhile to give this a closer review.

@php-pulls php-pulls closed this in b7689db Jan 5, 2021
@cmb69 cmb69 deleted the cmb/phar-zip-uaf branch January 5, 2021 13:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants