[packages/php/PHP_7_2] Rel 29. Fix user wrapper bailout bugs

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


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

    Rel 29. Fix user wrapper bailout bugs
    
    SplFileObject freed a borrowed name after a bailout in a user wrapper.
    User wrapper recursion guard outlived a bailout into the next request.

 php-spl-file-open-bailout.patch      | 60 ++++++++++++++++++++++++++++++++++++
 php-user-stream-filename-reset.patch | 24 +++++++++++++++
 php.spec                             |  7 ++++-
 3 files changed, 90 insertions(+), 1 deletion(-)
---
diff --git a/php.spec b/php.spec
index 73f483c..dcf779e 100644
--- a/php.spec
+++ b/php.spec
@@ -155,7 +155,7 @@ Summary(ru.UTF-8):	PHP Версии 7 - язык препроцессирова
 Summary(uk.UTF-8):	PHP Версії 7 - мова препроцесування HTML-файлів, виконувана на сервері
 Name:		%{orgname}%{php_suffix}
 Version:	7.2.34
-Release:	28
+Release:	29
 Epoch:		4
 # All files licensed under PHP version 3.01, except
 # Zend is licensed under Zend
@@ -380,6 +380,9 @@ Patch331:	php-cve-2026-129496.patch
 Patch332:	php-cve-2026-129474.patch
 Patch333:	php-cve-2026-129481.patch
 Patch334:	php-bug77185.patch
+# PLD-only: SplFileObject frees a borrowed file name after a bailout in a user wrapper
+Patch335:	php-spl-file-open-bailout.patch
+Patch336:	php-user-stream-filename-reset.patch
 URL:		https://www.php.net/
 %{?with_interbase:%{!?with_interbase_inst:BuildRequires:	Firebird-devel >= 1.0.2.908-2}}
 %{?with_pspell:BuildRequires:	aspell-devel >= 2:0.50.0}
@@ -2353,6 +2356,8 @@ cp -p php.ini-production php.ini
 %patch -P332 -p1
 %patch -P333 -p1
 %patch -P334 -p1
+%patch -P335 -p1
+%patch -P336 -p1
 
 sed -E -i -e '1s,#!\s*/usr/bin/env\s+(.*),#!%{__bindir}\1,' \
       run-tests.php
diff --git a/php-spl-file-open-bailout.patch b/php-spl-file-open-bailout.patch
new file mode 100644
index 0000000..3cd5a93
--- /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. exit(), 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 56e809b1..a7d34a1c 100644
+--- a/ext/spl/spl_directory.c
++++ b/ext/spl/spl_directory.c
+@@ -287,9 +287,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;
+@@ -302,7 +309,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;
+ 	}
+@@ -315,14 +324,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?
diff --git a/php-user-stream-filename-reset.patch b/php-user-stream-filename-reset.patch
new file mode 100644
index 0000000..82080eb
--- /dev/null
+++ b/php-user-stream-filename-reset.patch
@@ -0,0 +1,24 @@
+From d0b3096ff0f6f6f491833858f126a80f18b81151 Mon Sep 17 00:00:00 2001
+From: Dmitry Stogov <dmitry at zend.com>
+Date: Mon, 12 Sep 2022 11:38:31 +0300
+Subject: [PATCH] Reset FG(user_stream_current_filename) at the end of request
+
+A bailout inside a user stream wrapper's stream_open or dir_opendir left
+the recursion guard pointing into the finished request, so a later request
+of the same process could read freed memory and fail with "infinite
+recursion prevented" when it opened the same URL.
+
+Origin: upstream, https://github.com/php/php-src/commit/d0b3096ff0f6f6f491833858f126a80f18b81151
+---
+diff --git a/main/streams/streams.c b/main/streams/streams.c
+index 7207a066..caf38d31 100644
+--- a/main/streams/streams.c
++++ b/main/streams/streams.c
+@@ -1606,6 +1606,7 @@ static void stream_resource_persistent_dtor(zend_resource *rsrc)
+ 
+ void php_shutdown_stream_hashes(void)
+ {
++	FG(user_stream_current_filename) = NULL;
+ 	if (FG(stream_wrappers)) {
+ 		zend_hash_destroy(FG(stream_wrappers));
+ 		efree(FG(stream_wrappers));
================================================================

---- gitweb:

http://git.pld-linux.org/gitweb.cgi/packages/php.git/commitdiff/096ced79dedf29fd6fc4fbf6d9930e25056f6a94



More information about the pld-cvs-commit mailing list