Commit 5dd84e74855 for php

commit 5dd84e74855962e65a58079d1ed5f55dc09f514a
Author: Schwarzemann <barantbsd@gmail.com>
Date:   Mon Nov 23 17:26:18 2026 +0300

    ext/bz2: Fix NULL dereference when compress.bzip2:// open fails in write mode

    _php_stream_bz2open() first tries BZ2_bzopen() and, if that fails,
    falls back to php_stream_open_wrapper(). When the fallback also fails,
    *opened_path is NULL, but the write-mode cleanup still calls
    VCWD_UNLINK(ZSTR_VAL(*opened_path)).

    On ZTS builds VCWD_UNLINK goes through virtual_unlink(), which reads
    the path and segfaults. On NTS builds it is a plain unlink() syscall
    that receives a bogus pointer (0x18) and fails with EFAULT, so it
    does not crash but is still wrong.

    Check *opened_path before unlinking. The cleanup still runs when the
    fallback open succeeds but bz2 cannot take over the descriptor.

    Reproducer:

        dba_open("compress.bzip2:///nonexistent-dir/x", "nd", "flatfile");

    Closes GH-25674

diff --git a/ext/bz2/bz2.c b/ext/bz2/bz2.c
index f272e6d1741..6998c3134a5 100644
--- a/ext/bz2/bz2.c
+++ b/ext/bz2/bz2.c
@@ -255,7 +255,7 @@ PHP_BZ2_API php_stream *_php_stream_bz2open(php_stream_wrapper *wrapper,
 		/* remove the file created by php_stream_open_wrapper(), it is not needed since BZ2 functions
 		 * failed.
 		 */
-		if (opened_path && !bz_file && mode[0] == 'w') {
+		if (opened_path && *opened_path && !bz_file && mode[0] == 'w') {
 			VCWD_UNLINK(ZSTR_VAL(*opened_path));
 		}
 	}
diff --git a/ext/bz2/tests/dba_opened_path_null.phpt b/ext/bz2/tests/dba_opened_path_null.phpt
new file mode 100644
index 00000000000..d73730a58dc
--- /dev/null
+++ b/ext/bz2/tests/dba_opened_path_null.phpt
@@ -0,0 +1,16 @@
+--TEST--
+compress.bzip2:// opener must not unlink a NULL opened_path when the open fails
+--EXTENSIONS--
+bz2
+dba
+--SKIPIF--
+<?php
+if (!in_array('flatfile', dba_handlers())) die('skip flatfile handler not available');
+?>
+--FILE--
+<?php
+var_dump(dba_open("compress.bzip2://" . __DIR__ . "/nonexistent-dir/x", "nd", "flatfile"));
+?>
+--EXPECTF--
+Warning: dba_open(%S): Failed to open stream: operation failed in %s on line %d
+bool(false)