Commit 972d6673fc2 for php

commit 972d6673fc25046129cdf986fcbf0e22be5412e0
Author: David Carlier <devnexen@gmail.com>
Date:   Wed Nov 25 06:45:31 2026 +0000

    ext/phar: phar_archive_delref() double free on shared archive at shutdown.

    Objects outliving RSHUTDOWN dropped an empty archive at refcount 0
    through the already destroyed fname map, while another object still
    held it. The archive is now left to its last holder.

    Fix GH-25722
    Close GH-25728

diff --git a/NEWS b/NEWS
index 574b593c5fe..a37d4571799 100644
--- a/NEWS
+++ b/NEWS
@@ -207,6 +207,8 @@ PHP                                                                        NEWS
     freed private key). (Artem Ukrainskiy)
   . Fixed use-after-free when unsetting an entry with an open handle.
     (David Carlier)
+  . Fixed bug GH-25722 (phar_archive_delref() double free on shared archive at
+    shutdown). (David Carlier)

 - POSIX:
   . Fixed bug GH-25530 (posix_get_last_error() returns an error from a
diff --git a/ext/phar/phar.c b/ext/phar/phar.c
index 1bdc2d80336..d76b70206e7 100644
--- a/ext/phar/phar.c
+++ b/ext/phar/phar.c
@@ -294,7 +294,7 @@ bool phar_archive_delref(phar_archive_data *phar) /* {{{ */
 			remove_fname_cache |= phar->flags & PHAR_FILE_COMPRESSION_MASK;
 		}

-		if (remove_fname_cache) {
+		if (remove_fname_cache && !PHAR_G(request_ends)) {
 			if (zend_hash_str_del(&(PHAR_G(phar_fname_map)), phar->fname, phar->fname_len) != SUCCESS) {
 				phar_destroy_phar_data(phar);
 			}
diff --git a/ext/phar/tests/gh25722.phpt b/ext/phar/tests/gh25722.phpt
new file mode 100644
index 00000000000..8ecbb96fa2d
--- /dev/null
+++ b/ext/phar/tests/gh25722.phpt
@@ -0,0 +1,19 @@
+--TEST--
+GH-25722 (Double free of a phar archive shared by objects outliving request shutdown)
+--EXTENSIONS--
+phar
+--CREDITS--
+sgInnora
+--FILE--
+<?php
+$fname = __DIR__ . '/gh25722.tar';
+
+$p = new PharData($fname);
+$a = &$p;
+$q = new PharData($fname);
+$b = &$q;
+
+echo "Done", PHP_EOL;
+?>
+--EXPECT--
+Done