Commit cdc84d90e44 for php.net
commit cdc84d90e444accc6ca7b3b0093439142285b1c6
Author: Gina Peter Banyard <girgias@php.net>
Date: Wed Apr 22 05:21:03 2026 +0100
ext/phar: refactor phar_get_entry_data() to use a zend_string* for fname
diff --git a/ext/phar/phar_internal.h b/ext/phar/phar_internal.h
index 3ca4ac1ac16..6f5de58ca8d 100644
--- a/ext/phar/phar_internal.h
+++ b/ext/phar/phar_internal.h
@@ -467,7 +467,7 @@ void phar_entry_delref(phar_entry_data *idata);
phar_entry_info *phar_get_entry_info(phar_archive_data *phar, char *path, size_t path_len, char **error, bool security);
phar_entry_info *phar_get_entry_info_dir(phar_archive_data *phar, char *path, size_t path_len, char dir, char **error, bool security);
ZEND_ATTRIBUTE_NONNULL phar_entry_data *phar_get_or_create_entry_data(zend_string *fname, char *path, size_t path_len, const char *mode, char allow_dir, char **error, bool security, uint32_t timestamp);
-ZEND_ATTRIBUTE_NONNULL zend_result phar_get_entry_data(phar_entry_data **ret, const char *fname, size_t fname_len, char *path, size_t path_len, const char *mode, char allow_dir, char **error, bool security);
+ZEND_ATTRIBUTE_NONNULL zend_result phar_get_entry_data(phar_entry_data **ret, const zend_string *fname, char *path, size_t path_len, const char *mode, char allow_dir, char **error, bool security);
ZEND_ATTRIBUTE_NONNULL_ARGS(1, 4) int phar_flush_ex(phar_archive_data *archive, zend_string *user_stub, bool is_default_stub, char **error);
ZEND_ATTRIBUTE_NONNULL int phar_flush(phar_archive_data *archive, char **error);
zend_result phar_detect_phar_fname_ext(const char *filename, size_t filename_len, const char **ext_str, size_t *ext_len, int executable, int for_create, bool is_complete);
diff --git a/ext/phar/stream.c b/ext/phar/stream.c
index c56c100d52f..f745f4b7c57 100644
--- a/ext/phar/stream.c
+++ b/ext/phar/stream.c
@@ -240,7 +240,7 @@ static php_stream * phar_wrapper_open_url(php_stream_wrapper *wrapper, const cha
return NULL;
}
if (phar->is_tar || phar->is_zip) {
- if ((FAILURE == phar_get_entry_data(&idata, ZSTR_VAL(resource->host), ZSTR_LEN(resource->host), ".phar/stub.php", sizeof(".phar/stub.php")-1, "r", 0, &error, false)) || !idata) {
+ if ((FAILURE == phar_get_entry_data(&idata, resource->host, ".phar/stub.php", sizeof(".phar/stub.php")-1, "r", 0, &error, false)) || !idata) {
goto idata_error;
}
efree(internal_file);
@@ -288,7 +288,7 @@ static php_stream * phar_wrapper_open_url(php_stream_wrapper *wrapper, const cha
}
}
/* read-only access is allowed to magic files in .phar directory */
- if ((FAILURE == phar_get_entry_data(&idata, ZSTR_VAL(resource->host), ZSTR_LEN(resource->host), internal_file, strlen(internal_file), "r", 0, &error, false)) || !idata) {
+ if ((FAILURE == phar_get_entry_data(&idata, resource->host, internal_file, strlen(internal_file), "r", 0, &error, false)) || !idata) {
idata_error:
if (error) {
php_stream_wrapper_log_error(wrapper, options, "%s", error);
@@ -694,7 +694,7 @@ static int phar_wrapper_unlink(php_stream_wrapper *wrapper, const char *url, int
/* need to copy to strip leading "/", will get touched again */
internal_file = estrndup(ZSTR_VAL(resource->path) + 1, ZSTR_LEN(resource->path) - 1);
internal_file_len = ZSTR_LEN(resource->path) - 1;
- if (FAILURE == phar_get_entry_data(&idata, ZSTR_VAL(resource->host), ZSTR_LEN(resource->host), internal_file, internal_file_len, "r", 0, &error, true)) {
+ if (FAILURE == phar_get_entry_data(&idata, resource->host, internal_file, internal_file_len, "r", 0, &error, true)) {
/* constraints of fp refcount were not met */
if (error) {
php_stream_wrapper_log_error(wrapper, options, "unlink of \"%s\" failed: %s", url, error);
diff --git a/ext/phar/util.c b/ext/phar/util.c
index 9db0ba42a7f..efab7f9edab 100644
--- a/ext/phar/util.c
+++ b/ext/phar/util.c
@@ -466,7 +466,7 @@ ZEND_ATTRIBUTE_NONNULL static zend_result phar_separate_entry_fp(phar_entry_info
* appended, truncated, or read. For read, if the entry is marked unmodified, it is
* assumed that the file pointer, if present, is opened for reading
*/
-ZEND_ATTRIBUTE_NONNULL zend_result phar_get_entry_data(phar_entry_data **ret, const char *fname, size_t fname_len, char *path, size_t path_len, const char *mode, char allow_dir, char **error, bool security) /* {{{ */
+ZEND_ATTRIBUTE_NONNULL zend_result phar_get_entry_data(phar_entry_data **ret, const zend_string *fname, char *path, size_t path_len, const char *mode, char allow_dir, char **error, bool security) /* {{{ */
{
phar_archive_data *phar;
phar_entry_info *entry;
@@ -478,17 +478,17 @@ ZEND_ATTRIBUTE_NONNULL zend_result phar_get_entry_data(phar_entry_data **ret, co
*ret = NULL;
*error = NULL;
- if (FAILURE == phar_get_archive(&phar, fname, fname_len, NULL, 0, error)) {
+ if (FAILURE == phar_get_archive(&phar, ZSTR_VAL(fname), ZSTR_LEN(fname), NULL, 0, error)) {
return FAILURE;
}
if (for_write && PHAR_G(readonly) && !phar->is_data) {
- spprintf(error, 4096, "phar error: file \"%s\" in phar \"%s\" cannot be opened for writing, disabled by ini setting", path, fname);
+ spprintf(error, 4096, "phar error: file \"%s\" in phar \"%s\" cannot be opened for writing, disabled by ini setting", path, ZSTR_VAL(fname));
return FAILURE;
}
if (!path_len) {
- spprintf(error, 4096, "phar error: file \"\" in phar \"%s\" must not be empty", fname);
+ spprintf(error, 4096, "phar error: file \"\" in phar \"%s\" must not be empty", ZSTR_VAL(fname));
return FAILURE;
}
really_get_entry:
@@ -512,7 +512,7 @@ ZEND_ATTRIBUTE_NONNULL zend_result phar_get_entry_data(phar_entry_data **ret, co
if (for_write && phar->is_persistent) {
if (FAILURE == phar_copy_on_write(&phar)) {
- spprintf(error, 4096, "phar error: file \"%s\" in phar \"%s\" cannot be opened for writing, could not make cached phar writeable", path, fname);
+ spprintf(error, 4096, "phar error: file \"%s\" in phar \"%s\" cannot be opened for writing, could not make cached phar writeable", path, ZSTR_VAL(fname));
return FAILURE;
} else {
goto really_get_entry;
@@ -520,12 +520,12 @@ ZEND_ATTRIBUTE_NONNULL zend_result phar_get_entry_data(phar_entry_data **ret, co
}
if (entry->is_modified && !for_write) {
- spprintf(error, 4096, "phar error: file \"%s\" in phar \"%s\" cannot be opened for reading, writable file pointers are open", path, fname);
+ spprintf(error, 4096, "phar error: file \"%s\" in phar \"%s\" cannot be opened for reading, writable file pointers are open", path, ZSTR_VAL(fname));
return FAILURE;
}
if (entry->fp_refcount && for_write) {
- spprintf(error, 4096, "phar error: file \"%s\" in phar \"%s\" cannot be opened for writing, readable file pointers are open", path, fname);
+ spprintf(error, 4096, "phar error: file \"%s\" in phar \"%s\" cannot be opened for writing, readable file pointers are open", path, ZSTR_VAL(fname));
return FAILURE;
}
@@ -629,7 +629,7 @@ ZEND_ATTRIBUTE_NONNULL phar_entry_data *phar_get_or_create_entry_data(zend_strin
return NULL;
}
- if (FAILURE == phar_get_entry_data(&ret, ZSTR_VAL(fname), ZSTR_LEN(fname), path, path_len, mode, allow_dir, error, security)) {
+ if (FAILURE == phar_get_entry_data(&ret, fname, path, path_len, mode, allow_dir, error, security)) {
return NULL;
} else if (ret) {
return ret;