Skip to content

ext/phar: Refactor Phar to prevent unnecessary strlen() computations #11033

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 3 commits into from

Conversation

Girgias
Copy link
Member

@Girgias Girgias commented Apr 7, 2023

Based on top of #11032

We also make all checks for the stream wrapper protocol case-insensitive.

Minor drive-by code clean-up.

Copy link
Member

@dstogov dstogov left a comment

Choose a reason for hiding this comment

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

Looks good.
@iluuu1994 please also take a short look.

I didn't understand the removed code after zend_throw_exception_ex(). Note, it just set EG(exception) and doesn't perform C stack unwinding.

Comment on lines -485 to -493
if (path && path == entry) {
efree(entry);
}

if (arch) {
efree(arch);
}

goto finish;
Copy link
Member

Choose a reason for hiding this comment

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

Why this is removed?

Copy link
Member Author

Choose a reason for hiding this comment

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

The code outside the if branch is equivalent to this and performs the necessary clean-up and then jumps to finish

Copy link
Member

Choose a reason for hiding this comment

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

yeah, I see

@Girgias Girgias closed this in a72778b Apr 10, 2023
@Girgias Girgias deleted the phar-refactor branch April 10, 2023 12:24
@@ -256,17 +256,23 @@ zend_string *phar_find_in_include_path(zend_string *filename, phar_archive_data
return NULL;
}

fname = (char*)zend_get_executed_filename();
fname_len = strlen(fname);
zend_string *fname = zend_get_executed_filename_ex();
Copy link
Member

Choose a reason for hiding this comment

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

Contrary to zend_get_executed_filename() zend_get_executed_filename_ex() may return NULL. I don't know if this code can be triggered outside of user context. The same goes for the calls above.

return SUCCESS;
}

if (!strcmp(fname, "[no active file]")) {
if (zend_string_equals_literal(fname, "[no active file]")) {
Copy link
Member

Choose a reason for hiding this comment

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

This no longer makes sense, this string is only returned in zend_get_executed_filename(). This would now return NULL (and thus already segfault above).

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 indeed, surprised we don't have a test for that... AFAIK this only happens with eval()?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants