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

FilesystemPath::isFile returning true on non existent file #490

Closed
astrelsky opened this issue Feb 5, 2019 · 1 comment
Closed

FilesystemPath::isFile returning true on non existent file #490

astrelsky opened this issue Feb 5, 2019 · 1 comment
Assignees

Comments

@astrelsky
Copy link
Contributor

astrelsky commented Feb 5, 2019

I noticed that each implementation of FilesystemPath::isFile returns !isDirectory. The isDirectory functions appear to check whether the path is valid or exists and returns false if it is not. This causes instances of isFile to return true when the path may not even exist.

In the docstring it states "The path doesn't have to be loaded." Does this imply that it may not exist? If this is the case there may be instances where a non-existent file is not caught.

astrelsky pushed a commit to astrelsky/retdec that referenced this issue Feb 5, 2019
FilesystemPath::isFile was changed to return the result of it
not being a directory and if it exists. Resolves avast#490
@metthal metthal self-assigned this Feb 5, 2019
@metthal
Copy link
Member

metthal commented Feb 5, 2019

Thank you for the bug report. I see that you also fixed it yourself, so also thank you for that! Unfortunately it's in your PR about bin2pat, so I cannot merge it separately.

Just a note about your fix. I would prefer if FilesystemPathImplWindows::isFile() and FilesystemPathImplUnix::isFile() would actually check if the path is file as they should, because I think that your fix is workaround for broken isFile() implementation but it doesn't fix the root cause and that is how isFile() is implemented.

I suggest that FilesystemPathImplWindows::isFile() should check if FILE_ATTRIBUTE_DIRECTORY bit is not set and FilesystemPathImplUnix::isFile() should check for S_ISREG(st.st_mode).

astrelsky pushed a commit to astrelsky/retdec that referenced this issue Feb 5, 2019
metthal pushed a commit that referenced this issue Feb 10, 2019
* Fixed FilesystemPath::isFile return value.

Resolves #490

* Refactoring of FilesystemPathImplWindows

Instances of reinterpret_cast<HANDLE>(-1) in
FilesystemPathImplWindows have been replaced with
INVALID_HANDLE_VALUE for readability. GetFileAttributes was
utilized in place of FindFirstFile to check for file existance
and file attributes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants