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

fix file_exists relative path bug #7932

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion hphp/runtime/ext/std/ext_std_file.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,15 @@ static int accessSyscall(
return -1;
}
}
return ::access(File::TranslatePathWithFileCache(path).data(), mode);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this change will disable the StaticFileCache feature.

The cause of this bug is that FileUtil::canonicalize is used in File::TranslatePathWithFileCache and File::TranslatePathKeepRelative. So what's the purpose of FileUtil::canonicalize? It a path is canonicalized, the access() result may be different.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think FileCache has no meaning, please see the code (File: TranslatePathWithFileCache),the logic is :
!translated.empty() && access(translated.data(), F_OK) < 0 && StaticContentCache::TheFileCache

so the physical file does not exist, and then the file cache won't exist.
I don't think this code is meaningful.

String filepath = path;
if (path.charAt(0) != '/') {
String cwd = g_context->getCwd();
filepath = cwd + "/" + path;
if (!cwd.empty() && cwd[cwd.length() - 1] == '/') {
filepath = cwd + path;
}
return ::access(filepath.data(),mode);
}
}
return w->access(uri_or_path, mode);
}
Expand Down
9 changes: 9 additions & 0 deletions hphp/test/slow/file/relative_path.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php
error_reporting(-1);
$dir = "hhvm_file_exists_test";
mkdir($dir);
file_put_contents($dir."/a.txt","test");
var_dump(file_exists($dir."/b/../a.txt"));
unlink($dir."/a.txt");
rmdir($dir);
?>
1 change: 1 addition & 0 deletions hphp/test/slow/file/relative_path.php.expectf
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
bool(false)