[packages/php/PHP_8_1] Rel 9. Fix user wrapper bailout bugs

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


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

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

 php-spl-file-open-bailout.patch | 54 +++++++++++++++++++++++++++++++++++++++++
 php.spec                        |  5 +++-
 2 files changed, 58 insertions(+), 1 deletion(-)
---
diff --git a/php.spec b/php.spec
index e26a014..d53da55 100644
--- a/php.spec
+++ b/php.spec
@@ -149,7 +149,7 @@ Summary(ru.UTF-8):	PHP - язык препроцессирования HTML-фа
 Summary(uk.UTF-8):	PHP - мова препроцесування HTML-файлів, виконувана на сервері
 Name:		%{orgname}%{php_suffix}
 Version:	8.1.34
-Release:	8
+Release:	9
 Epoch:		4
 # All files licensed under PHP version 3.01, except
 # Zend is licensed under Zend
@@ -245,6 +245,8 @@ Patch225:	php-cve-2026-128064.patch
 Patch226:	php-cve-2026-127960.patch
 Patch227:	php-cve-2026-129474.patch
 Patch228:	php-cve-2026-129481.patch
+# PLD-only: SplFileObject frees a borrowed file name after a bailout in a user wrapper
+Patch229:	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}
@@ -1976,6 +1978,7 @@ cp -p php.ini-production php.ini
 %patch -P226 -p1
 %patch -P227 -p1
 %patch -P228 -p1
+%patch -P229 -p1
 
 sed -E -i -e '1s,#!\s*/usr/bin/env\s+(.*),#!%{__bindir}\1,' \
       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..483b52b
--- /dev/null
+++ b/php-spl-file-open-bailout.patch
@@ -0,0 +1,54 @@
+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; shivammathur/php-src-backports and remicollet/php-src-security
+have no fix.
+---
+diff --git a/ext/spl/spl_directory.c b/ext/spl/spl_directory.c
+index b00a1e66..91f57055 100644
+--- a/ext/spl/spl_directory.c
++++ b/ext/spl/spl_directory.c
+@@ -311,10 +311,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;
+@@ -329,7 +333,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;
+ 	}
+ 
+@@ -341,9 +346,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/9652942b9bc3065708002cbd4a2ac1b4d900ab45



More information about the pld-cvs-commit mailing list