Skip to content

fix: a read must open the file that was listed - #32

Closed
petecleary wants to merge 2 commits into
release-0.8.0from
fix/0.8.0-read-race
Closed

petecleary wants to merge 2 commits into
release-0.8.0from
fix/0.8.0-read-race

Conversation

@petecleary

Copy link
Copy Markdown
Contributor

The directory-source part of the fix in moca-reader-typescript #50 and moca-reader-dotnet #34: a link swapped in after listing, at the file or at a folder on its path, is not followed.

Before: on POSIX this Reader already opened each folder and the file relative to the one before with O_NOFOLLOW, and checked the open handle. Where there is no O_NOFOLLOW (Windows), it checked each step of the path with lstat and then opened the file by path, so a folder swapped for a link between the checks and the open was followed.

Now: the directory source records each listed file's device and inode (st_dev, st_ino; on Windows the volume and file index), and both read paths refuse an open file that is not the one listed.

Test: test_the_step_by_step_check_refuses_a_folder_swapped_after_the_checks drives the Windows path (sys.platform patched) and swaps content/ for a link to an outside folder just before the open. Added in the first commit, where it fails.

Check (against moca-spec v0.7.0, this branch's pin):

$ uv run pytest tests/test_malformed_input.py -q -k "step_by_step"   # on the test-only commit
FAILED tests/test_malformed_input.py::test_the_step_by_step_check_refuses_a_folder_swapped_after_the_checks
1 failed, 1 passed, 27 deselected in 0.91s

$ uv run pytest -q   # with the fix
849 passed, 39 skipped in 17.76s
$ uv run ruff check
All checks passed!
$ uv run ruff format --check
90 files already formatted
$ uv run mypy
Success: no issues found in 50 source files

OpenMOCA added 2 commits November 28, 2026 22:12
… its checks

Fails on this commit: on the Windows path each step is checked, then the file is opened by path, so a folder swapped for a link in between is followed.
The directory source records each listed file's device and inode, and the open handle must match them. This closes the gap in the step-by-step check used where there is no O_NOFOLLOW (Windows): a folder swapped for a link between the checks and the open.
@petecleary

Copy link
Copy Markdown
Contributor Author

This work continues in 0.8.0

@petecleary petecleary closed this Dec 1, 2026
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.

1 participant