Skip to content

fix: report unreadable files as existing in StreamWrapper::url_stat - #47

Closed
MohannadElemary wants to merge 1 commit into
pestphp:5.xfrom
MohannadElemary:fix/stream-wrapper-stat-unreadable-files
Closed

MohannadElemary wants to merge 1 commit into
pestphp:5.xfrom
MohannadElemary:fix/stream-wrapper-stat-unreadable-files

Conversation

@MohannadElemary

Copy link
Copy Markdown

Fixes pestphp/pest#1949.

url_stat() returned false whenever is_readable() was false. But stat() only needs search permission on the parent directory, so under --mutate a chmod 0000 file looked missing to file_exists(), is_file() and filesize(). Code that checks a file before fopen() never reached its "could not open" branch, so mutants there stayed UNTESTED.

This checks file_exists() (or is_link() for lstat) instead and keeps the stat/lstat behaviour. 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 phpstan reports 2 errors that are already on 5.x. I haven't run a full mutation run end to end; I verified the stat behaviour directly and with the unit test.

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.
@MohannadElemary

Copy link
Copy Markdown
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.

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

Successfully merging this pull request may close these issues.

[Bug]: --mutate hides unreadable files, so mutants behind a failed read can never be killed

1 participant