Skip to content

ext/phar: avoid redundant allocation by using zend_string for alias#21785

Open
arshidkv12 wants to merge 4 commits intophp:masterfrom
arshidkv12:phar-5
Open

ext/phar: avoid redundant allocation by using zend_string for alias#21785
arshidkv12 wants to merge 4 commits intophp:masterfrom
arshidkv12:phar-5

Conversation

@arshidkv12
Copy link
Copy Markdown
Contributor

No description provided.

Copy link
Copy Markdown
Member

@iluuu1994 iluuu1994 left a comment

Choose a reason for hiding this comment

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

No technical review performed.

Comment thread ext/phar/zip.c Outdated
}

if (!actual_alias && zend_string_equals_literal(entry.filename, ".phar/alias.txt")) {
if (actual_alias == NULL && zend_string_equals_literal(entry.filename, ".phar/alias.txt")) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Please avoid changes like this. There are others in this PR.

Comment thread ext/phar/zip.c Outdated
mydata->is_temporary_alias = 0;

if (NULL != (fd_ptr = zend_hash_str_find_ptr(&(PHAR_G(phar_alias_map)), actual_alias, mydata->alias_len))) {
if (NULL != (fd_ptr = zend_hash_str_find_ptr(&(PHAR_G(phar_alias_map)), ZSTR_VAL(actual_alias), ZSTR_LEN(actual_alias)))) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Indentation is broken.

@iluuu1994
Copy link
Copy Markdown
Member

@Girgias Would you like to review this? I saw you make some phar PRs, I don't know if that means you're interested in getting more familiar with it?

@Girgias Girgias self-assigned this Apr 17, 2026
@Girgias
Copy link
Copy Markdown
Member

Girgias commented Apr 17, 2026

I'm currently in the process of making the code of it simpler to understand. I usually spend some time every year to do this :)

Copy link
Copy Markdown
Member

@Girgias Girgias left a comment

Choose a reason for hiding this comment

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

I'm not really happy with the approach here. ext/phar is a complicated extensions and the "avoid reallocations" TODOs mostly involve actually modifying the structs to use zend_strings. Not just use them sporadically.

Especially as you seem to "blindly" be doing some changes without changing surrounding context that would benefit from using zend_strings.

Comment thread ext/phar/zip.c
mydata->is_temporary_alias = 0;

if (NULL != (fd_ptr = zend_hash_str_find_ptr(&(PHAR_G(phar_alias_map)), actual_alias, mydata->alias_len))) {
if (NULL != (fd_ptr = zend_hash_str_find_ptr(&(PHAR_G(phar_alias_map)), ZSTR_VAL(actual_alias), ZSTR_LEN(actual_alias)))) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Indent, but you have a zend_string use the HashTable API that uses zend_string...

Comment thread ext/phar/zip.c
zend_hash_str_add_ptr(&(PHAR_G(phar_fname_map)), mydata->fname, fname_len, mydata);

if (actual_alias) {
if (actual_alias != NULL) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Don't change this, the not equal to NULL syntax is quite confusing.

Suggested change
if (actual_alias != NULL) {
if (actual_alias) {

Comment thread ext/phar/zip.c
Comment on lines +663 to +664
actual_alias = php_stream_copy_to_mem(fp, entry.uncompressed_filesize, 0);
entry.uncompressed_filesize = ZSTR_LEN(actual_alias);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I don't see how you are actually following the TODO comment here.

Comment thread ext/phar/zip.c
Comment on lines +652 to +653
actual_alias = php_stream_copy_to_mem(fp, entry.uncompressed_filesize, 0);
entry.uncompressed_filesize = ZSTR_LEN(actual_alias);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Ditto, not following the TODO comment.

Comment thread ext/phar/zip.c
Comment on lines +632 to +633
actual_alias = php_stream_copy_to_mem(fp, entry.uncompressed_filesize, 0);
entry.uncompressed_filesize = ZSTR_LEN(actual_alias);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Ditto

Comment thread ext/phar/zip.c
Comment on lines +344 to +347
if (actual_alias) { \
zend_string_release_ex(actual_alias, 0); \
actual_alias = NULL; \
} \
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is very fishy.

Comment thread ext/phar/zip.c
Comment on lines +724 to 725
zend_string_release_ex(actual_alias, 0);
zend_hash_str_add_ptr(&(PHAR_G(phar_alias_map)), mydata->alias, mydata->alias_len, mydata);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Once again we have the zend_string to check the HashTable.

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