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

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


commit 57e6cd7d990390d1a2dcd67f98bc9c7cc83ee5a4
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 | 60 +++++++++++++++++++++++++++++++++++++++++
 php.spec                        |  5 +++-
 2 files changed, 64 insertions(+), 1 deletion(-)
---
diff --git a/php.spec b/php.spec
index 66a2262..c873589 100644
--- a/php.spec
+++ b/php.spec
@@ -148,7 +148,7 @@ Summary(ru.UTF-8):	PHP - язык препроцессирования HTML-фа
 Summary(uk.UTF-8):	PHP - мова препроцесування HTML-файлів, виконувана на сервері
 Name:		%{orgname}%{php_suffix}
 Version:	8.0.30
-Release:	2
+Release:	3
 Epoch:		4
 # All files licensed under PHP version 3.01, except
 # Zend is licensed under Zend
@@ -268,6 +268,8 @@ Patch250:	php-cve-2026-129474.patch
 Patch251:	php-cve-2026-129481.patch
 Patch252:	php-cve-2026-7258-sapi.patch
 Patch253:	php-cve-2025-1735-leak.patch
+# PLD-only: SplFileObject frees a borrowed file name after a bailout in a user wrapper
+Patch254:	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}
@@ -2026,6 +2028,7 @@ cp -p php.ini-production php.ini
 %patch -P251 -p1
 %patch -P252 -p1
 %patch -P253 -p1
+%patch -P254 -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..efd2ffa
--- /dev/null
+++ b/php-spl-file-open-bailout.patch
@@ -0,0 +1,60 @@
+Subject: [PATCH] spl: own the SplFileObject file name before opening it
+
+spl_filesystem_file_open() kept pointing at the caller's file name 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 an interned literal or another SplFileInfo's name (invalid or
+double 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 8646ba20..0c50f622 100644
+--- a/ext/spl/spl_directory.c
++++ b/ext/spl/spl_directory.c
+@@ -290,9 +290,16 @@ static int spl_filesystem_file_open(spl_filesystem_object *intern, int use_inclu
+ 
+ 	intern->type = SPL_FS_FILE;
+ 
++	/* both are borrowed from the caller; copy them before user wrapper code can
++	 * bail out, as spl_filesystem_object_free_storage() frees file_name */
++	intern->file_name = estrndup(intern->file_name, intern->file_name_len);
++	intern->u.file.open_mode = estrndup(intern->u.file.open_mode, intern->u.file.open_mode_len);
++
+ 	php_stat(intern->file_name, intern->file_name_len, FS_IS_DIR, &tmp);
+ 	if (Z_TYPE(tmp) == IS_TRUE) {
++		efree(intern->u.file.open_mode);
+ 		intern->u.file.open_mode = NULL;
++		efree(intern->file_name);
+ 		intern->file_name = NULL;
+ 		zend_throw_exception_ex(spl_ce_LogicException, 0, "Cannot use SplFileObject with directories");
+ 		return FAILURE;
+@@ -305,7 +312,9 @@ static int spl_filesystem_file_open(spl_filesystem_object *intern, int use_inclu
+ 		if (!EG(exception)) {
+ 			zend_throw_exception_ex(spl_ce_RuntimeException, 0, "Cannot open file '%s'", intern->file_name_len ? intern->file_name : "");
+ 		}
+-		intern->file_name = NULL; /* until here it is not a copy */
++		efree(intern->file_name);
++		intern->file_name = NULL;
++		efree(intern->u.file.open_mode);
+ 		intern->u.file.open_mode = NULL;
+ 		return FAILURE;
+ 	}
+@@ -318,14 +327,11 @@ static int spl_filesystem_file_open(spl_filesystem_object *intern, int use_inclu
+ 	*/
+ 
+ 	if (intern->file_name_len > 1 && IS_SLASH_AT(intern->file_name, intern->file_name_len-1)) {
+-		intern->file_name_len--;
++		intern->file_name[--intern->file_name_len] = '\0';
+ 	}
+ 
+ 	intern->orig_path = estrndup(intern->u.file.stream->orig_path, strlen(intern->u.file.stream->orig_path));
+ 
+-	intern->file_name = estrndup(intern->file_name, intern->file_name_len);
+-	intern->u.file.open_mode = estrndup(intern->u.file.open_mode, intern->u.file.open_mode_len);
+-
+ 	/* avoid reference counting in debug mode, thus do it manually */
+ 	ZVAL_RES(&intern->u.file.zresource, intern->u.file.stream->res);
+ 	/*!!! TODO: maybe bug?
================================================================

---- gitweb:

http://git.pld-linux.org/gitweb.cgi/packages/php.git/commitdiff/57e6cd7d990390d1a2dcd67f98bc9c7cc83ee5a4



More information about the pld-cvs-commit mailing list