[php-src] Issue #9227: Filenames with leading dots or spaces are not properly handled
| From: | cmb69 | Date: | Tue, 02 Aug 2022 13:12:54 +0000 |
| Subject: | [php-src] Issue #9227: Filenames with leading dots or spaces are not properly handled | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-242102@lists.php.net to get a copy of this message | ||
Issue: https://github.com/php/php-src/issues/9227
Author: cmb69
### Description
The following code:
```php
<?php
var_dump(realpath(__DIR__ . "/ntfs.txt."));
var_dump(file_put_contents(__DIR__ . "/ntfs.txt", "bar"));
var_dump(realpath(__DIR__ . "/ntfs.txt."));
```
Resulted in this output:
```
bool(false)
int(3)
string(35) "C:\php-sdk\phpdev\vs16\x64\ntfs.txt"
```
But I expected this output instead:
```
bool(false)
int(3)
bool(false)
```
This happens regardless of NTS or ZTS builds. The very same happens for trailing spaces. The basic
problem is that [Windows treats filenames with trailing spaces or dots in a special
way](https://docs.microsoft.com/en-us/troubleshoot/windows-client/shell-experience/file-folder-name-whitespace-characters),
namely that these are basically ignored by most APIs. That article also mentions that leading spaces
would be ignored, but I cannot reproduce this (Windows 21H1); maybe that has been changed in the
meantime.
Anyhow, the current behavior is very confusing, and doesn't match other systems. Furthermore,
there is actually code which is supposed to catch these cases (trailing spaces and dots), and to
report
ERROR_ACCESS_DENIED:
https://github.com/php/php-src/blob/4679805cd69f99d9f545f3c8f599112edc15c58d/win32/ioutil.h#L156-L169
However, this code is not exercised in many cases, since "normalization" occurs before the
code is reached.
### PHP Version
all supported versions
### Operating System
Windows