[packages/php/PHP_8_2] Rel 3. Fix user wrapper bailout bugs

arekm arekm at pld-linux.org
Fri Nov 20 08:14:21 CET 2026


commit 1762cf32806092dbf1918384c3b2b4c9a744455a
Author: Arkadiusz Miśkiewicz <arekm at maven.pl>
Date:   Fri Nov 20 08:06:52 2026 +0100

    Rel 3. Fix user wrapper bailout bugs
    
    SplFileObject freed a borrowed name after a bailout in a user wrapper.

 php-spl-file-open-bailout.patch | 53 +++++++++++++++++++++++++++++++++++++++++
 php.spec                        |  5 +++-
 2 files changed, 57 insertions(+), 1 deletion(-)
---
diff --git a/php.spec b/php.spec
index fb56373..d976b99 100644
--- a/php.spec
+++ b/php.spec
@@ -142,7 +142,7 @@
 %define		ver_suffix	82
 %define		php_suffix	%{!?with_default_php:%{ver_suffix}}
 %define		subver		%{nil}
-%define		rel		2
+%define		rel		3
 Summary:	PHP: Hypertext Preprocessor
 Summary(fr.UTF-8):	Le langage de script embarque-HTML PHP
 Summary(pl.UTF-8):	Język skryptowy PHP
@@ -211,6 +211,8 @@ Patch71:	libdb-info.patch
 Patch72:	opcache-revalidate-path-once.patch
 Patch73:	CVE-2026-129481.patch
 Patch74:	CVE-2026-129474.patch
+# PLD-only: SplFileObject frees a borrowed file name after a bailout in a user wrapper
+Patch75:	php-spl-file-open-bailout.patch
 URL:		https://www.php.net/
 %{?with_pdo_firebird:%{!?with_interbase_inst:BuildRequires:	Firebird-devel >= 1.0.2.908-2}}
 %{?with_pspell:BuildRequires:	aspell-devel >= 2:0.50.0}
@@ -1914,6 +1916,7 @@ cp -p php.ini-production php.ini
 %patch -P72 -p1
 %patch -P73 -p1
 %patch -P74 -p1
+%patch -P75 -p1
 
 %{__sed} -i -e '1s,/usr/bin/env php,%{_bindir}/php,' \
 	ext/ext_skel.php \
diff --git a/php-spl-file-open-bailout.patch b/php-spl-file-open-bailout.patch
new file mode 100644
index 0000000..3018acc
--- /dev/null
+++ b/php-spl-file-open-bailout.patch
@@ -0,0 +1,53 @@
+Subject: [PATCH] spl: own the SplFileObject file name before opening it
+
+spl_filesystem_file_open() kept the caller's file name without a reference
+until the open succeeded. A fatal error or a timeout inside a user stream
+wrapper's url_stat or stream_open left it there, and the object's free then
+released a reference it did not own: after SplFileInfo::openFile() the
+source object's name was released twice (use after free at shutdown).
+
+PLD-only: php-src (master too) still borrows the name until the open
+succeeds.
+---
+diff --git a/ext/spl/spl_directory.c b/ext/spl/spl_directory.c
+index e0fe1292..93c53484 100644
+--- a/ext/spl/spl_directory.c
++++ b/ext/spl/spl_directory.c
+@@ -339,10 +339,14 @@ static zend_result spl_filesystem_file_open(spl_filesystem_object *intern, bool
+ 	zval tmp;
+ 
+ 	intern->type = SPL_FS_FILE;
++	/* file_name is borrowed from the caller; take a reference before user wrapper
++	 * code can bail out, as spl_filesystem_object_free_storage() releases it */
++	intern->file_name = zend_string_copy(intern->file_name);
+ 	php_stat(intern->file_name, FS_IS_DIR, &tmp);
+ 	if (Z_TYPE(tmp) == IS_TRUE) {
+ 		zend_string_release(intern->u.file.open_mode);
+ 		intern->u.file.open_mode = NULL;
++		zend_string_release(intern->file_name);
+ 		intern->file_name = NULL;
+ 		zend_throw_exception_ex(spl_ce_LogicException, 0, "Cannot use SplFileObject with directories");
+ 		return FAILURE;
+@@ -357,7 +361,8 @@ static zend_result spl_filesystem_file_open(spl_filesystem_object *intern, bool
+ 		}
+ 		zend_string_release(intern->u.file.open_mode);
+ 		intern->u.file.open_mode = NULL;
+-		intern->file_name = NULL; /* until here it is not a copy */
++		zend_string_release(intern->file_name);
++		intern->file_name = NULL;
+ 		return FAILURE;
+ 	}
+ 
+@@ -372,9 +377,9 @@ static zend_result spl_filesystem_file_open(spl_filesystem_object *intern, bool
+ 	*/
+ 
+ 	if (ZSTR_LEN(intern->file_name) > 1 && IS_SLASH_AT(ZSTR_VAL(intern->file_name), ZSTR_LEN(intern->file_name)-1)) {
+-		intern->file_name = zend_string_init(ZSTR_VAL(intern->file_name), ZSTR_LEN(intern->file_name)-1, 0);
+-	} else {
+-		intern->file_name = zend_string_copy(intern->file_name);
++		zend_string *file_name = zend_string_init(ZSTR_VAL(intern->file_name), ZSTR_LEN(intern->file_name)-1, 0);
++		zend_string_release(intern->file_name);
++		intern->file_name = file_name;
+ 	}
+ 
+ 	intern->orig_path = zend_string_init(intern->u.file.stream->orig_path, strlen(intern->u.file.stream->orig_path), 0);
================================================================

---- gitweb:

http://git.pld-linux.org/gitweb.cgi/packages/php.git/commitdiff/1762cf32806092dbf1918384c3b2b4c9a744455a



More information about the pld-cvs-commit mailing list