Repository navigation
fix: report unreadable files as existing in StreamWrapper::url_stat - #47
Closed
MohannadElemary wants to merge 1 commit into
Closed
MohannadElemary wants to merge 1 commit into
MohannadElemary wants to merge 1 commit into
Conversation
stat() only needs search permission on the parent directory, not read permission on the file. Guarding url_stat() with is_readable() made file_exists(), is_file() and filesize() return false for a file that exists but cannot be read, so code that stats a file before fopen() never reached its failed-read branch and the mutants there stayed UNTESTED. Check for existence instead and keep stat()/lstat() semantics.
Author
|
Closing this for now, it's a niche case with only one report and I'd rather not change what the stream wrapper reports about unreadable files without a real project showing it matters. Happy to revisit if more people hit it. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes pestphp/pest#1949.
url_stat()returnedfalsewheneveris_readable()was false. Butstat()only needs search permission on the parent directory, so under--mutateachmod 0000file looked missing tofile_exists(),is_file()andfilesize(). Code that checks a file beforefopen()never reached its "could not open" branch, so mutants there stayed UNTESTED.This checks
file_exists()(oris_link()forlstat) instead and keeps thestat/lstatbehaviour. I added a unit test that stages an unreadable file and checks the three functions, plus one for a missing file. The first test fails without the fix. It is skipped when run as root.Caveats: I could not run the visual snapshot tests (no coverage driver in my environment), and
phpstanreports 2 errors that are already on5.x. I haven't run a full mutation run end to end; I verified the stat behaviour directly and with the unit test.