fix: eliminate TOCTOU race in RunState.load() - #3908
Open
Quratulain-bilal wants to merge 2 commits into
Open
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Eliminates the RunState.load() TOCTOU race by handling missing files during open().
Changes:
- Replaces the
exists()pre-check with exception handling. - Preserves the custom missing-state error.
Show a summary per file
| File | Description |
|---|---|
src/specify_cli/workflows/engine.py |
Makes run-state loading race-safe. |
Review details
Tip
Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
- Files reviewed: 1/1 changed files
- Comments generated: 2
- Review effort level: Balanced
Remove exists() pre-check and wrap open() in try/except FileNotFoundError to provide a clear custom error message even under race conditions.
- Update docstring to describe the direct open() read instead of the removed exists() probe, keeping the security rationale accurate. - Add test_load_not_found_custom_message: verifies the custom 'Run state not found:' error message is raised. - Add test_load_not_found_no_exists_probe: patches builtins.open to raise FileNotFoundError and asserts the custom message, proving the TOCTOU-eliminated code path works correctly.
Quratulain-bilal
force-pushed
the
fix/load-state-toctou-v2
branch
from
August 10, 2026 21:18
0ec8d31 to
c010d11
Compare
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.
Problem
RunState.load()checksexists()then callsopen(). Between the two calls the file can be deleted, causing a rawFileNotFoundErrorinstead of the intended custom message.Fix
Remove the
exists()pre-check and wrapopen()intry/except FileNotFoundError.Testing