Skip to content

ext/phar: mark fields as const#21825

Merged
Girgias merged 2 commits intophp:masterfrom
Girgias:2026-04-phar-const-field
Apr 22, 2026
Merged

ext/phar: mark fields as const#21825
Girgias merged 2 commits intophp:masterfrom
Girgias:2026-04-phar-const-field

Conversation

@Girgias
Copy link
Copy Markdown
Member

@Girgias Girgias commented Apr 21, 2026

No description provided.

Girgias added 2 commits April 21, 2026 22:13
This char* is derived from the fname char* field.
As this is derived from a live char* pointer where we don't have the ownership.
Comment thread ext/phar/phar_internal.h
/* The ext field stores the location of the file extension from the fname field, and thus should never be freed. */
uint32_t ext_len;
char *ext;
const char *ext;
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.

Do you actually need to store the ext string, or do you only need the length? Memory and gut tells me you only need the length

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Haven't fully looked into this, as I mainly wanted to split this change out of #21823 :) but happy to look into it to double-check if it is needed as this whole thing does seem slightly dubious

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I guess the one case that requires closer investigation is the usage of phar_detect_phar_fname_ext() in phar_rename_archive() as this sets the ext field. But it does seem indeed like neither the ext_len nor ext are really used for anything?

Makes me think that refactoring phar_detect_phar_fname_ext() to return an enum of PATH_IS_URL|USE_ALIAS|IS_TAR|IS_ZIP|IS_PHAR might be more sensible.

Anyhow, I'll merge the PR as is to unblock the fname to zend_string conversion, but will definitely have another look at this ext field mess :)

@Girgias Girgias marked this pull request as ready for review April 22, 2026 03:38
@Girgias Girgias merged commit 60b2d0d into php:master Apr 22, 2026
19 checks passed
@Girgias Girgias deleted the 2026-04-phar-const-field branch April 22, 2026 03:53
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.

2 participants