Skip to content
Open
Changes from 3 commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
5c1194d
ext/phar: avoid redundant allocation by using zend_string for alias
arshidkv12 Apr 17, 2026
98b1601
ext/phar: avoid redundant allocation by using zend_string for alias
arshidkv12 Apr 17, 2026
b41aa38
ext/phar: avoid redundant allocation by using zend_string for alias
arshidkv12 Apr 17, 2026
8b9558e
ext/phar: avoid redundant allocation by using zend_string for alias
arshidkv12 Apr 17, 2026
33f5cb7
ext/phar: avoid redundant allocation by using zend_string for alias
arshidkv12 Apr 18, 2026
3a623c6
ext/phar: avoid redundant allocation by using zend_string for alias
arshidkv12 Apr 18, 2026
35abbaf
ext/phar/utils.c: Change if guard to assertion in phar_get_link_locat…
Girgias Apr 17, 2026
f5b17c2
gen_stub: fix invalid C variable name for namespaced types in union/i…
GromNaN Apr 17, 2026
9e6857c
gen_stub: support use statements in stub files (#21784)
GromNaN Apr 17, 2026
1f1aa34
Merge branch 'master' into phar-5
arshidkv12 Apr 18, 2026
ead31bd
ext/phar: avoid redundant allocation by using zend_string for alias
arshidkv12 Apr 18, 2026
9aef6eb
ext/phar: avoid redundant allocation by using zend_string for alias
arshidkv12 Apr 18, 2026
ae62c7c
ext/phar: avoid redundant allocation by using zend_string for alias
arshidkv12 Apr 18, 2026
2c2b3c9
ext/phar: avoid redundant allocation by using zend_string for alias
arshidkv12 Apr 18, 2026
98b7702
Update ext/phar/phar_object.c
arshidkv12 Apr 18, 2026
c0fe93c
Update ext/phar/phar_object.c
arshidkv12 Apr 18, 2026
f416bb0
ext/phar: avoid redundant allocation by using zend_string for alias
arshidkv12 Apr 19, 2026
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
80 changes: 23 additions & 57 deletions ext/phar/zip.c
Original file line number Diff line number Diff line change
Expand Up @@ -232,9 +232,9 @@ zend_result phar_parse_zipfile(php_stream *fp, const char *fname, size_t fname_l
uint16_t i;
phar_archive_data *mydata = NULL;
phar_entry_info entry = {0};
char *ext, *actual_alias = NULL;
char *ext = NULL;
char *metadata = NULL;

zend_string *actual_alias = NULL;
size = php_stream_tell(fp);

if (size > sizeof(locator) + 65536) {
Expand Down Expand Up @@ -341,7 +341,10 @@ zend_result phar_parse_zipfile(php_stream *fp, const char *fname, size_t fname_l
entry.fp_type = PHAR_FP;
entry.is_persistent = mydata->is_persistent;
#define PHAR_ZIP_FAIL(errmsg) \
efree(actual_alias); \
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.

zend_hash_destroy(&mydata->manifest); \
HT_INVALIDATE(&mydata->manifest); \
zend_hash_destroy(&mydata->mounted_dirs); \
Expand Down Expand Up @@ -600,7 +603,7 @@ zend_result phar_parse_zipfile(php_stream *fp, const char *fname, size_t fname_l
ZVAL_UNDEF(&entry.metadata_tracker.val);
}

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.

php_stream_filter *filter;

/* archive alias found */
Expand All @@ -626,20 +629,8 @@ zend_result phar_parse_zipfile(php_stream *fp, const char *fname, size_t fname_l

php_stream_filter_append(&fp->readfilters, filter);

// TODO: refactor to avoid reallocation ???
//??? entry.uncompressed_filesize = php_stream_copy_to_mem(fp, &actual_alias, entry.uncompressed_filesize, 0)
{
zend_string *str = php_stream_copy_to_mem(fp, entry.uncompressed_filesize, 0);
if (str) {
entry.uncompressed_filesize = ZSTR_LEN(str);
actual_alias = estrndup(ZSTR_VAL(str), ZSTR_LEN(str));
zend_string_release_ex(str, 0);
} else {
actual_alias = NULL;
entry.uncompressed_filesize = 0;
}
}

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

if (!entry.uncompressed_filesize) {
php_stream_filter_remove(filter, 1);
zend_string_release_ex(entry.filename, entry.is_persistent);
Expand All @@ -658,21 +649,8 @@ zend_result phar_parse_zipfile(php_stream *fp, const char *fname, size_t fname_l
}

php_stream_filter_append(&fp->readfilters, filter);

// TODO: refactor to avoid reallocation ???
//??? entry.uncompressed_filesize = php_stream_copy_to_mem(fp, &actual_alias, entry.uncompressed_filesize, 0)
{
zend_string *str = php_stream_copy_to_mem(fp, entry.uncompressed_filesize, 0);
if (str) {
entry.uncompressed_filesize = ZSTR_LEN(str);
actual_alias = estrndup(ZSTR_VAL(str), ZSTR_LEN(str));
zend_string_release_ex(str, 0);
} else {
actual_alias = NULL;
entry.uncompressed_filesize = 0;
}
}

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.

if (!entry.uncompressed_filesize) {
php_stream_filter_remove(filter, 1);
zend_string_release_ex(entry.filename, entry.is_persistent);
Expand All @@ -682,20 +660,8 @@ zend_result phar_parse_zipfile(php_stream *fp, const char *fname, size_t fname_l
php_stream_filter_flush(filter, 1);
php_stream_filter_remove(filter, 1);
} else {
// TODO: refactor to avoid reallocation ???
//??? entry.uncompressed_filesize = php_stream_copy_to_mem(fp, &actual_alias, entry.uncompressed_filesize, 0)
{
zend_string *str = php_stream_copy_to_mem(fp, entry.uncompressed_filesize, 0);
if (str) {
entry.uncompressed_filesize = ZSTR_LEN(str);
actual_alias = estrndup(ZSTR_VAL(str), ZSTR_LEN(str));
zend_string_release_ex(str, 0);
} else {
actual_alias = NULL;
entry.uncompressed_filesize = 0;
}
}

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.

if (!entry.uncompressed_filesize) {
zend_string_release_ex(entry.filename, entry.is_persistent);
PHAR_ZIP_FAIL("unable to read in alias, truncated");
Expand Down Expand Up @@ -725,37 +691,37 @@ zend_result phar_parse_zipfile(php_stream *fp, const char *fname, size_t fname_l

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) {

phar_archive_data *fd_ptr;

if (!phar_validate_alias(actual_alias, mydata->alias_len)) {
if (!phar_validate_alias(ZSTR_VAL(actual_alias), ZSTR_LEN(actual_alias))) {
if (error) {
spprintf(error, 4096, "phar error: invalid alias \"%s\" in zip-based phar \"%s\"", actual_alias, fname);
spprintf(error, 4096, "phar error: invalid alias \"%s\" in zip-based phar \"%s\"", ZSTR_VAL(actual_alias), fname);
}
efree(actual_alias);
zend_string_release_ex(actual_alias, 0);
zend_hash_str_del(&(PHAR_G(phar_fname_map)), mydata->fname, fname_len);
return FAILURE;
}

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.

if (SUCCESS != phar_free_alias(fd_ptr)) {
if (error) {
spprintf(error, 4096, "phar error: Unable to add zip-based phar \"%s\" with implicit alias, alias is already in use", fname);
}
efree(actual_alias);
zend_string_release_ex(actual_alias, 0);
zend_hash_str_del(&(PHAR_G(phar_fname_map)), mydata->fname, fname_len);
return FAILURE;
}
}

mydata->alias = entry.is_persistent ? pestrndup(actual_alias, mydata->alias_len, 1) : actual_alias;

if (entry.is_persistent) {
efree(actual_alias);
mydata->alias = pestrndup(ZSTR_VAL(actual_alias), ZSTR_LEN(actual_alias), 1);
} else {
mydata->alias = estrndup(ZSTR_VAL(actual_alias), ZSTR_LEN(actual_alias));
}

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.

} else {
phar_archive_data *fd_ptr;
Expand Down
Loading