Skip to content

Consistent support for NTFS streams #9230

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
cmb69 opened this issue Aug 2, 2022 · 0 comments · May be fixed by #9231
Open

Consistent support for NTFS streams #9230

cmb69 opened this issue Aug 2, 2022 · 0 comments · May be fixed by #9231

Comments

@cmb69
Copy link
Member

cmb69 commented Aug 2, 2022

Description

The following code:

<?php
$filename = __DIR__ . "/ntfs.txt:foo";
var_dump(file_put_contents($filename, "bar"));
var_dump(file_get_contents($filename));
var_dump(file_exists($filename));
var_dump(realpath($filename));
var_dump(@stat($filename) !== false);
var_dump(basename($filename));
var_dump(file_exists(basename($filename)));

Resulted in this output for NTS builds:

int(3)
string(3) "bar"
bool(true)
bool(false)
bool(true)
string(12) "ntfs.txt:foo"
bool(false)

Resulted in this output for ZTS builds:

int(3)
string(3) "bar"
bool(false)
bool(false)
bool(false)
string(12) "ntfs.txt:foo"
bool(false)

As shown, the support for NTFS streams is totally inconsistent. Reading and writing such streams is supported, but file_exists() and stat() behave differently for NTS and ZTS builds (and even differently for NTS streams depending on whether an absolute or relative path is given). realpath() always fails.

Furthermore, pathinfo() and friends report the stream name as part of the filename, usually even as part of the file extension.

This (dangerous) inconsistency should be resolved one way or another. It might be best to completely remove support for NTFS streams for plain files, mostly to be consistent with other systems, and to avoid confusion for userland developers. A simple solution would be to "reject" such filenames, i.e. report permission denied when trying to access them. If we do this, pathinfo() and friends can likely stay as is.

If support for NTFS streams is desireable, we could introduce a new stream wrapper (say ntfs://) which would make NTFS stream access explicit.

PHP Version

all supported versions

Operating System

Windows

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant