Skip to content

ext/phar: only .phar extensions in file names trigger automatic archive detection - #23260

Merged
LamentXU123 merged 3 commits into
php:masterfrom
LamentXU123:phar
Aug 14, 2026
Merged

ext/phar: only .phar extensions in file names trigger automatic archive detection#23260
LamentXU123 merged 3 commits into
php:masterfrom
LamentXU123:phar

Conversation

@LamentXU123

@LamentXU123 LamentXU123 commented Aug 13, 2026

Copy link
Copy Markdown
Member

So we don't trigger the .phar unserialization process when include files like or .pharabcd/1.html. Only treat them as phar files when the .phar is in the filename instead of path, so we can still support include 1.phar.zip include 1.phar.gz but not .pharabcd/1.html

Also, if the char after .phar is not a . (which happens in e.g. quality.pharma.report.txt) they are not treated as phar files when included as well.

@LamentXU123
LamentXU123 marked this pull request as draft August 13, 2026 18:49
@LamentXU123 LamentXU123 changed the title ext/phar: Only treat files with a .phar suffix as phar files when including ext/phar: .phar in a directory name does not trigger automatic archive detection Aug 13, 2026
@LamentXU123 LamentXU123 changed the title ext/phar: .phar in a directory name does not trigger automatic archive detection ext/phar: .phar in a directory name should not trigger automatic archive detection Aug 13, 2026
@LamentXU123
LamentXU123 marked this pull request as ready for review August 13, 2026 19:22
Comment thread ext/phar/phar.c

zend_op_array *(*phar_orig_compile_file)(zend_file_handle *file_handle, int type);

static bool phar_has_marker_in_filename(const zend_string *filename)

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 think to really properly fix it, we should check if the filename ends with .phar or .phar.zip or .phar.tar etc, one of those supported extensions. I believe somewhere in ext/phar the code already lists the possible extensions, but I may be wrong.
Now, with this code, something like quality.pharma.report.txt would still trigger ;)

@LamentXU123 LamentXU123 Aug 13, 2026

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 believe somewhere in ext/phar the code already lists the possible extensions

Sadly there aren't :( and since the phar extension is very, very old. There are conventions in different code bases all over the world and I couldn't find a place where people finally reach an agreement on what suffix should a valid phar file have.

There are things like .phar.php .phar.zip.php or whatever.

Now, with this code, something like quality.pharma.report.txt would still trigger ;)

Clever catch ;)

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.

There are things like .phar.php .phar.zip.php or whatever.

😭

@LamentXU123 LamentXU123 changed the title ext/phar: .phar in a directory name should not trigger automatic archive detection ext/phar: only .phar extensions in file names trigger automatic archive detection Aug 13, 2026
@LamentXU123
LamentXU123 merged commit 5332ab0 into php:master Aug 14, 2026
18 checks passed
@LamentXU123
LamentXU123 deleted the phar branch August 14, 2026 19:00
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