From 86a3b0db675c52f8778d22ebf6c72c8ee164b22f Mon Sep 17 00:00:00 2001 From: Marc Date: Tue, 22 Sep 2026 14:04:15 +0200 Subject: [PATCH] fix windows ci: w11 no longer treats names like NUL.txt as reserved --- .../tests/file/ghsa-9f67-6fw4-hpfp-win32.phpt | 22 ++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/ext/standard/tests/file/ghsa-9f67-6fw4-hpfp-win32.phpt b/ext/standard/tests/file/ghsa-9f67-6fw4-hpfp-win32.phpt index d83260e5507e..27104f12b4a8 100644 --- a/ext/standard/tests/file/ghsa-9f67-6fw4-hpfp-win32.phpt +++ b/ext/standard/tests/file/ghsa-9f67-6fw4-hpfp-win32.phpt @@ -22,12 +22,28 @@ foreach (['NUL', 'nul:', '\\\\.\\NUL'] as $name) { } echo "Reserved names in paths are rejected:\n"; -foreach (['NUL', 'con', 'COM1', 'LPT9', 'CONIN$', 'NUL.txt', 'con.php', 'aux:stream', 'NUL .txt', 'NUL :txt', '.\\NUL'] as $name) { +foreach (['NUL', 'con', 'COM1', 'LPT9', 'CONIN$', '.\\NUL'] as $name) { $blocked = $dir . DIRECTORY_SEPARATOR . $name; var_dump(@fopen($blocked, 'wb') === false); var_dump(file_exists($blocked)); } -var_dump(@fopen('NUL.txt', 'wb') === false); + +echo "Suffixed device names:\n"; +foreach (['NUL.txt', 'con.php', 'aux:stream', 'NUL .txt', 'NUL :txt'] as $name) { + $file = $dir . DIRECTORY_SEPARATOR . $name; + $h = @fopen($file, 'wb'); + if (PHP_WINDOWS_VERSION_BUILD < 22000) { + var_dump($h === false); + } else { + // Windows 11 treats these as regular files + var_dump(is_resource($h) && (fstat($h)['mode'] & 0170000) === 0100000); + fclose($h); + // Delete the base file and its streams + $base = $dir . DIRECTORY_SEPARATOR . explode(':', $name)[0]; + unlink('\\\\.\\' . $base . '::$DATA'); + } + var_dump(file_exists($file)); +} var_dump(@stat($dir . DIRECTORY_SEPARATOR . 'NUL') === false); var_dump(@mkdir($dir . DIRECTORY_SEPARATOR . 'NUL') === false); var_dump(@rename(__FILE__, $dir . DIRECTORY_SEPARATOR . 'PRN') === false); @@ -61,6 +77,7 @@ bool(true) bool(false) bool(true) bool(false) +Suffixed device names: bool(true) bool(false) bool(true) @@ -75,7 +92,6 @@ bool(true) bool(true) bool(true) bool(true) -bool(true) Similar names are fine: bool(true) bool(true)