Skip to content
This repository has been archived by the owner on Jan 8, 2020. It is now read-only.

Use file_exists to check for an uploaded file. #6664

Merged
merged 2 commits into from
Sep 16, 2014

Conversation

akrabat
Copy link
Contributor

@akrabat akrabat commented Sep 11, 2014

It turns out that stream_resolve_include_path doesn't work for a default
Windows install where upload_tmp_dir is set to C:\Windows\Temp. I'm
unclear if this is intended PHP behaviour or not, but the upload file
validator should not be checking for a file of the same name on the
include path regardless.

It turns out that stream_resolve_include_path doesn't work for a default
Windows install where upload_tmp_dir is set to C:\Windows\Temp. I'm
unclear if this is intended PHP behaviour or not, but the upload file
validator should not be checking for a file of the same name on the
include path regardless.
@@ -74,7 +74,7 @@ public function isValid($value)

switch ($error) {
case UPLOAD_ERR_OK:
if (empty($file) || false === stream_resolve_include_path($file)) {
if (empty($file) || false === file_exists($file)) {
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 is_file() is more specific, because file_exists() also returns true when it is a directory. It looks to me using file_exists() creates a way for hackers to "scan" the system for specific folders?

@akrabat
Copy link
Contributor Author

akrabat commented Sep 15, 2014

Good point @Martin-P. I've updated the PR.

weierophinney added a commit that referenced this pull request Sep 16, 2014
Use file_exists to check for an uploaded file.
weierophinney added a commit that referenced this pull request Sep 16, 2014
@weierophinney weierophinney added this to the 2.3.3 milestone Sep 16, 2014
@weierophinney weierophinney self-assigned this Sep 16, 2014
@weierophinney weierophinney merged commit e23eac0 into zendframework:master Sep 16, 2014
weierophinney added a commit that referenced this pull request Sep 16, 2014
@ThaDafinser
Copy link
Contributor

@akrabat seems to be still a bug on windows with default path.

Not in this validator, but in Zend\Validator\File\Size and many others:
https://github.com/zendframework/zf2/search?q=stream_resolve_include_path&type=Code&utf8=%E2%9C%93

weierophinney added a commit to zendframework/zend-validator that referenced this pull request May 15, 2015
…ix/uploadfile

Use file_exists to check for an uploaded file.
weierophinney added a commit to zendframework/zend-validator that referenced this pull request May 15, 2015
weierophinney added a commit to zendframework/zend-validator that referenced this pull request May 15, 2015
# for free to subscribe to this conversation on GitHub. Already have an account? #.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants