Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 2 additions & 1 deletion NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ PHP NEWS

- Zlib:
. deflate_init() now raises a TypeError when the value for option
"strategy" is not of type int. (Weilin Du)
"level", "memory", "window", or "strategy" is not of type int.
(Weilin Du)

<<< NOTE: Insert NEWS from last stable release here prior to actual release! >>>
2 changes: 1 addition & 1 deletion UPGRADING
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ PHP 8.6 UPGRADE NOTES

- Zlib:
. deflate_init() now raises a TypeError when the value for option
"strategy" is not of type int.
"level", "memory", "window", or "strategy" is not of type int.

========================================
2. New Features
Expand Down
12 changes: 10 additions & 2 deletions Zend/zend_API.h
Original file line number Diff line number Diff line change
Expand Up @@ -524,8 +524,16 @@ ZEND_API const char *zend_get_type_by_const(int type);
#define DLEXPORT
#endif

#define array_init(arg) ZVAL_ARR((arg), zend_new_array(0))
#define array_init_size(arg, size) ZVAL_ARR((arg), zend_new_array(size))
static zend_always_inline void array_init_size(zval *arg, uint32_t size)
{
ZVAL_ARR(arg, zend_new_array(size));
}

static zend_always_inline void array_init(zval *arg)
{
array_init_size(arg, 0);
}

ZEND_API void object_init(zval *arg);
ZEND_API zend_result object_init_ex(zval *arg, zend_class_entry *ce);
ZEND_API zend_result object_init_with_constructor(zval *arg, zend_class_entry *class_type, uint32_t param_count, zval *params, HashTable *named_params);
Expand Down
4 changes: 3 additions & 1 deletion Zend/zend_portability.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,9 @@
#endif

/* pseudo fallthrough keyword; */
#if defined(__GNUC__) && __GNUC__ >= 7
#if __STDC_VERSION__ >= 202311L || defined(__cplusplus)
# define ZEND_FALLTHROUGH [[fallthrough]]
#elif defined(__GNUC__) && __GNUC__ >= 7
# define ZEND_FALLTHROUGH __attribute__((__fallthrough__))
#else
# define ZEND_FALLTHROUGH ((void)0)
Expand Down
20 changes: 8 additions & 12 deletions ext/phar/dirstream.c
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,6 @@ static php_stream *phar_make_dirstream(const char *dir, size_t dirlen, const Has
php_stream *phar_wrapper_open_dir(php_stream_wrapper *wrapper, const char *path, const char *mode, int options, zend_string **opened_path, php_stream_context *context STREAMS_DC) /* {{{ */
{
char *error;
phar_archive_data *phar;

php_url *resource = phar_parse_url(wrapper, path, mode, options);
if (!resource) {
Expand Down Expand Up @@ -276,7 +275,8 @@ php_stream *phar_wrapper_open_dir(php_stream_wrapper *wrapper, const char *path,

phar_request_initialize();

if (FAILURE == phar_get_archive(&phar, ZSTR_VAL(resource->host), ZSTR_LEN(resource->host), NULL, 0, &error)) {
const phar_archive_data *phar = phar_get_archive(ZSTR_VAL(resource->host), ZSTR_LEN(resource->host), NULL, 0, &error);
if (!phar) {
if (error) {
php_stream_wrapper_log_error(wrapper, options, "%s", error);
efree(error);
Expand Down Expand Up @@ -340,7 +340,6 @@ php_stream *phar_wrapper_open_dir(php_stream_wrapper *wrapper, const char *path,
int phar_wrapper_mkdir(php_stream_wrapper *wrapper, const char *url_from, int mode, int options, php_stream_context *context) /* {{{ */
{
phar_entry_info entry;
phar_archive_data *phar = NULL;
char *error;
php_url *resource = NULL;

Expand All @@ -351,9 +350,7 @@ int phar_wrapper_mkdir(php_stream_wrapper *wrapper, const char *url_from, int mo
return 0;
}

if (FAILURE == phar_get_archive(&phar, ZSTR_VAL(arch), ZSTR_LEN(arch), NULL, 0, NULL)) {
phar = NULL;
}
phar_archive_data *phar = phar_get_archive(ZSTR_VAL(arch), ZSTR_LEN(arch), NULL, 0, NULL);

zend_string_release_ex(arch, false);

Expand All @@ -379,7 +376,8 @@ int phar_wrapper_mkdir(php_stream_wrapper *wrapper, const char *url_from, int mo
return 0;
}

if (FAILURE == phar_get_archive(&phar, ZSTR_VAL(resource->host), ZSTR_LEN(resource->host), NULL, 0, &error)) {
phar = phar_get_archive(ZSTR_VAL(resource->host), ZSTR_LEN(resource->host), NULL, 0, &error);
if (!phar) {
php_stream_wrapper_log_error(wrapper, options, "phar error: cannot create directory \"%s\" in phar \"%s\", error retrieving phar information: %s", ZSTR_VAL(resource->path) + 1, ZSTR_VAL(resource->host), error);
efree(error);
php_url_free(resource);
Expand Down Expand Up @@ -467,7 +465,6 @@ int phar_wrapper_mkdir(php_stream_wrapper *wrapper, const char *url_from, int mo
*/
int phar_wrapper_rmdir(php_stream_wrapper *wrapper, const char *url, int options, php_stream_context *context) /* {{{ */
{
phar_archive_data *phar = NULL;
char *error;

/* pre-readonly check, we need to know if this is a data phar */
Expand All @@ -477,9 +474,7 @@ int phar_wrapper_rmdir(php_stream_wrapper *wrapper, const char *url, int options
return 0;
}

if (FAILURE == phar_get_archive(&phar, ZSTR_VAL(arch), ZSTR_LEN(arch), NULL, 0, NULL)) {
phar = NULL;
}
phar_archive_data *phar = phar_get_archive(ZSTR_VAL(arch), ZSTR_LEN(arch), NULL, 0, NULL);

zend_string_release_ex(arch, false);

Expand All @@ -506,7 +501,8 @@ int phar_wrapper_rmdir(php_stream_wrapper *wrapper, const char *url, int options
return 0;
}

if (FAILURE == phar_get_archive(&phar, ZSTR_VAL(resource->host), ZSTR_LEN(resource->host), NULL, 0, &error)) {
phar = phar_get_archive(ZSTR_VAL(resource->host), ZSTR_LEN(resource->host), NULL, 0, &error);
if (!phar) {
php_stream_wrapper_log_error(wrapper, options, "phar error: cannot remove directory \"%s\" in phar \"%s\", error retrieving phar information: %s", ZSTR_VAL(resource->path)+1, ZSTR_VAL(resource->host), error);
efree(error);
php_url_free(resource);
Expand Down
20 changes: 9 additions & 11 deletions ext/phar/func_interceptors.c
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ static zend_string* phar_get_name_for_relative_paths(zend_string *filename, bool

/* fopen within phar, if :// is not in the url, then prepend phar://<archive>/ */
/* retrieving a file defaults to within the current directory, so use this if possible */
phar_archive_data *phar;
if (FAILURE == phar_get_archive(&phar, ZSTR_VAL(arch), ZSTR_LEN(arch), NULL, 0, NULL)) {
phar_archive_data *phar = phar_get_archive(ZSTR_VAL(arch), ZSTR_LEN(arch), NULL, 0, NULL);
if (!phar) {
zend_string_release_ex(arch, false);
return NULL;
}
Expand Down Expand Up @@ -492,9 +492,9 @@ static void phar_file_stat(const char *filename, size_t filename_length, int typ
zend_string *arch = phar_split_fname(ZSTR_VAL(fname), ZSTR_LEN(fname), NULL, 2, 0);
if (arch) {
/* fopen within phar, if :// is not in the url, then prepend phar://<archive>/ */
zend_result has_archive = phar_get_archive(&phar, ZSTR_VAL(arch), ZSTR_LEN(arch), NULL, 0, NULL);
phar = phar_get_archive(ZSTR_VAL(arch), ZSTR_LEN(arch), NULL, 0, NULL);
zend_string_release_ex(arch, false);
if (FAILURE == has_archive) {
if (!phar) {
goto skip_phar;
}
splitted:;
Expand Down Expand Up @@ -727,13 +727,13 @@ PHP_FUNCTION(phar_is_file) /* {{{ */

zend_string *arch = phar_split_fname(ZSTR_VAL(fname), ZSTR_LEN(fname), NULL, 2, 0);
if (arch) {
phar_archive_data *phar;
;

/* fopen within phar, if :// is not in the url, then prepend phar://<archive>/ */
/* retrieving a file within the current directory, so use this if possible */
zend_result has_archive = phar_get_archive(&phar, ZSTR_VAL(arch), ZSTR_LEN(arch), NULL, 0, NULL);
phar_archive_data *phar = phar_get_archive(ZSTR_VAL(arch), ZSTR_LEN(arch), NULL, 0, NULL);
zend_string_release_ex(arch, false);
if (has_archive == SUCCESS) {
if (phar) {
phar_entry_info *etemp;

zend_string *entry = phar_fix_filepath(filename, filename_len, true);
Expand Down Expand Up @@ -784,13 +784,11 @@ PHP_FUNCTION(phar_is_link) /* {{{ */

zend_string *arch = phar_split_fname(ZSTR_VAL(fname), ZSTR_LEN(fname), NULL, 2, 0);
if (arch) {
phar_archive_data *phar;

/* fopen within phar, if :// is not in the url, then prepend phar://<archive>/ */
/* retrieving a file within the current directory, so use this if possible */
zend_result has_archive = phar_get_archive(&phar, ZSTR_VAL(arch), ZSTR_LEN(arch), NULL, 0, NULL);
phar_archive_data *phar = phar_get_archive(ZSTR_VAL(arch), ZSTR_LEN(arch), NULL, 0, NULL);
zend_string_release_ex(arch, false);
if (has_archive == SUCCESS) {
if (phar) {
phar_entry_info *etemp;

zend_string *entry = phar_fix_filepath(filename, filename_len, true);
Expand Down
5 changes: 2 additions & 3 deletions ext/phar/phar.c
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,6 @@ ZEND_ATTRIBUTE_NONNULL void phar_entry_remove(phar_entry_data *idata, char **err
*/
static zend_result phar_open_parsed_phar(char *fname, size_t fname_len, char *alias, size_t alias_len, bool is_data, uint32_t options, phar_archive_data** pphar, char **error) /* {{{ */
{
phar_archive_data *phar;
#ifdef PHP_WIN32
char *save_fname;
ALLOCA_FLAG(fname_use_heap)
Expand All @@ -504,12 +503,12 @@ static zend_result phar_open_parsed_phar(char *fname, size_t fname_len, char *al
phar_unixify_path_separators(fname, fname_len);
}
#endif
zend_result archive_retrieved = phar_get_archive(&phar, fname, fname_len, alias, alias_len, error);
phar_archive_data *phar = phar_get_archive(fname, fname_len, alias, alias_len, error);
/* logic is as follows:
- If no alias was passed in, then it can match either and be valid
- If an explicit alias was requested, ensure the filename passed in matches the phar's filename.
*/
bool process_phar = SUCCESS == archive_retrieved && (!alias || zend_string_equals_cstr(phar->fname, fname, fname_len));
bool process_phar = phar && (!alias || zend_string_equals_cstr(phar->fname, fname, fname_len));
#ifdef PHP_WIN32
if (fname != save_fname) {
free_alloca(fname, fname_use_heap);
Expand Down
4 changes: 2 additions & 2 deletions ext/phar/phar_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -411,8 +411,8 @@ ZEND_ATTRIBUTE_NONNULL_ARGS(1, 6, 7) zend_result phar_open_or_create_filename(ze
ZEND_ATTRIBUTE_NONNULL_ARGS(1, 6, 7) zend_result phar_create_or_parse_filename(zend_string *fname, char *alias, size_t alias_len, bool is_data, uint32_t options, phar_archive_data** pphar, char **error);
ZEND_ATTRIBUTE_NONNULL_ARGS(3) zend_result phar_open_executed_filename(char *alias, size_t alias_len, char **error);
zend_result phar_free_alias(const phar_archive_data *phar);
zend_result phar_get_archive(phar_archive_data **archive, const char *fname, size_t fname_len, const char *alias, size_t alias_len, char **error);
zend_result phar_verify_signature(php_stream *fp, size_t end_of_phar, uint32_t sig_type, char *sig, size_t sig_len, const char *fname, char **signature, size_t *signature_len, char **error);
phar_archive_data* phar_get_archive(const char *fname, size_t fname_len, const char *alias, size_t alias_len, char **error);
zend_result phar_verify_signature(php_stream *fp, size_t end_of_phar, uint32_t sig_type, const char *sig, size_t sig_len, const char *fname, char **signature, size_t *signature_len, char **error);
ZEND_ATTRIBUTE_NONNULL zend_string* phar_create_signature(phar_archive_data *phar, php_stream *fp, char **error);

/* utility functions */
Expand Down
8 changes: 4 additions & 4 deletions ext/phar/phar_object.c
Original file line number Diff line number Diff line change
Expand Up @@ -752,8 +752,8 @@ PHP_METHOD(Phar, webPhar)
entry_len = sizeof("/index.php")-1;
}

if (FAILURE == phar_get_archive(&phar, fname, fname_len, NULL, 0, NULL) ||
(info = phar_get_entry_info(phar, entry, entry_len, NULL, false)) == NULL) {
phar = phar_get_archive(fname, fname_len, NULL, 0, NULL);
if (!phar || (info = phar_get_entry_info(phar, entry, entry_len, NULL, false)) == NULL) {
phar_do_404(phar, fname, fname_len, f404);
} else {
char *tmp = NULL, sa = '\0';
Expand Down Expand Up @@ -793,8 +793,8 @@ PHP_METHOD(Phar, webPhar)
goto cleanup_skip_entry;
}

if (FAILURE == phar_get_archive(&phar, fname, fname_len, NULL, 0, NULL) ||
(info = phar_get_entry_info(phar, entry, entry_len, NULL, false)) == NULL) {
phar = phar_get_archive(fname, fname_len, NULL, 0, NULL);
if (!phar || (info = phar_get_entry_info(phar, entry, entry_len, NULL, false)) == NULL) {
phar_do_404(phar, fname, fname_len, f404);
goto cleanup;
}
Expand Down
21 changes: 10 additions & 11 deletions ext/phar/stream.c
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,8 @@ static php_stream * phar_wrapper_open_url(php_stream_wrapper *wrapper, const cha
} else {
if (!*internal_file && (options & STREAM_OPEN_FOR_INCLUDE)) {
/* retrieve the stub */
if (FAILURE == phar_get_archive(&phar, ZSTR_VAL(resource->host), ZSTR_LEN(resource->host), NULL, 0, NULL)) {
phar = phar_get_archive(ZSTR_VAL(resource->host), ZSTR_LEN(resource->host), NULL, 0, NULL);
if (!phar) {
php_stream_wrapper_log_error(wrapper, options, "file %s is not a valid phar archive", ZSTR_VAL(resource->host));
efree(internal_file);
php_url_free(resource);
Expand Down Expand Up @@ -554,7 +555,6 @@ static int phar_wrapper_stat(php_stream_wrapper *wrapper, const char *url, int f
php_stream_statbuf *ssb, php_stream_context *context) /* {{{ */
{
char *internal_file;
phar_archive_data *phar;
size_t internal_file_len;

php_url *resource = phar_parse_url(wrapper, url, "r", flags|PHP_STREAM_URL_STAT_QUIET);
Expand All @@ -577,7 +577,8 @@ static int phar_wrapper_stat(php_stream_wrapper *wrapper, const char *url, int f

internal_file = ZSTR_VAL(resource->path) + 1; /* strip leading "/" */
/* find the phar in our trusty global hash indexed by alias (host of phar://blah.phar/file.whatever) */
if (FAILURE == phar_get_archive(&phar, ZSTR_VAL(resource->host), ZSTR_LEN(resource->host), NULL, 0, NULL)) {
phar_archive_data *phar = phar_get_archive(ZSTR_VAL(resource->host), ZSTR_LEN(resource->host), NULL, 0, NULL);
if (!phar) {
php_url_free(resource);
return FAILURE;
}
Expand Down Expand Up @@ -725,7 +726,6 @@ static int phar_wrapper_unlink(php_stream_wrapper *wrapper, const char *url, int
static int phar_wrapper_rename(php_stream_wrapper *wrapper, const char *url_from, const char *url_to, int options, php_stream_context *context) /* {{{ */
{
char *error;
phar_archive_data *phar, *pfrom, *pto;
bool is_dir = false;
bool is_modified = false;

Expand All @@ -736,9 +736,8 @@ static int phar_wrapper_rename(php_stream_wrapper *wrapper, const char *url_from
php_error_docref(NULL, E_WARNING, "phar error: cannot rename \"%s\" to \"%s\": invalid or non-writable url \"%s\"", url_from, url_to, url_from);
return 0;
}
if (SUCCESS != phar_get_archive(&pfrom, ZSTR_VAL(resource_from->host), ZSTR_LEN(resource_from->host), NULL, 0, NULL)) {
pfrom = NULL;
}

phar_archive_data *pfrom = phar_get_archive(ZSTR_VAL(resource_from->host), ZSTR_LEN(resource_from->host), NULL, 0, NULL);
if (PHAR_G(readonly) && (!pfrom || !pfrom->is_data)) {
php_url_free(resource_from);
php_error_docref(NULL, E_WARNING, "phar error: Write operations disabled by the php.ini setting phar.readonly");
Expand All @@ -751,9 +750,8 @@ static int phar_wrapper_rename(php_stream_wrapper *wrapper, const char *url_from
php_error_docref(NULL, E_WARNING, "phar error: cannot rename \"%s\" to \"%s\": invalid or non-writable url \"%s\"", url_from, url_to, url_to);
return 0;
}
if (SUCCESS != phar_get_archive(&pto, ZSTR_VAL(resource_to->host), ZSTR_LEN(resource_to->host), NULL, 0, NULL)) {
pto = NULL;
}

phar_archive_data *pto = phar_get_archive(ZSTR_VAL(resource_to->host), ZSTR_LEN(resource_to->host), NULL, 0, NULL);
if (PHAR_G(readonly) && (!pto || !pto->is_data)) {
php_url_free(resource_from);
php_url_free(resource_to);
Expand Down Expand Up @@ -797,7 +795,8 @@ static int phar_wrapper_rename(php_stream_wrapper *wrapper, const char *url_from
return 0;
}

if (SUCCESS != phar_get_archive(&phar, ZSTR_VAL(resource_from->host), ZSTR_LEN(resource_from->host), NULL, 0, &error)) {
phar_archive_data *phar = phar_get_archive(ZSTR_VAL(resource_from->host), ZSTR_LEN(resource_from->host), NULL, 0, &error);
if (!phar) {
php_url_free(resource_from);
php_url_free(resource_to);
php_error_docref(NULL, E_WARNING, "phar error: cannot rename \"%s\" to \"%s\": %s", url_from, url_to, error);
Expand Down
Loading