Skip to content
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

../ is not correctly recognized in VfsStream #267

Closed
Sanderluc5 opened this issue Sep 9, 2021 · 2 comments
Closed

../ is not correctly recognized in VfsStream #267

Sanderluc5 opened this issue Sep 9, 2021 · 2 comments

Comments

@Sanderluc5
Copy link

Sanderluc5 commented Sep 9, 2021

I'm currently trying out some functionality that's normally working fine in native filesystems. But the the problem is that ../ and ./ are not working as intended. It seems ../ is not recognized as going directory back etc.

For example this is the code i tested:

$root = vfsStream::setup('');

mkdir('vfs://etc');
file_put_contents('vfs://etc/../test', 'test');
echo file_get_contents('vfs://test');

I'm getting the following error:

Warning: file_get_contents(vfs://test): Failed to open stream: "org\bovigo\vfs\vfsStreamWrapper::stream_open" call failed

I expect to create the file /test. But instead the file /etc/test gets created. Is this some kind of bug? I'm currently working on a Path Traversal simulation so this would be a very nice functionality to have.

@bizurkur
Copy link
Contributor

bizurkur commented Sep 9, 2021

This is because of #211. vfsStream doesn't support a blank name (/) for root. So what's happening is it thinks etc is root and won't let you create files above that level.

If you modify your test slightly, things work:

$root = vfsStream::setup('root'); // <-- giving a name for root is the important part
$root = vfsStream::setup(); // <-- this is the same as above
mkdir($root->url() . '/etc');
file_put_contents($root->url() . '/etc/../test', 'test');
echo file_get_contents($root->url() . '/test');

Closing as #211 is the issue.


If you absolutely need / as the root name "right now" you could try mockfs. It's the exact same concept as vfs, but has some key differences. The test you're trying to do here works in mockfs.

use MockFileSystem\MockFileSystem as mockfs;

mockfs::create();
mkdir('mfs:///etc'); // note the three `/`. Two are for the scheme separator, one is to designate root.
file_put_contents('mfs:///etc/../test', 'test');
echo file_get_contents('mfs:///test');
// prints "test"

@bizurkur bizurkur closed this as completed Sep 9, 2021
@Sanderluc5
Copy link
Author

MockFS is exactly what i needed. Thanks for your time and efforts.

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

No branches or pull requests

2 participants