Skip to content

fix: remove TOCTOU race in RunState.load - #3839

Open
Quratulain-bilal wants to merge 1 commit into
github:mainfrom
Quratulain-bilal:fix/load-state-toctou
Open

fix: remove TOCTOU race in RunState.load#3839
Quratulain-bilal wants to merge 1 commit into
github:mainfrom
Quratulain-bilal:fix/load-state-toctou

Conversation

@Quratulain-bilal

Copy link
Copy Markdown
Contributor

Summary

Remove exists() check before open() and catch FileNotFoundError directly to prevent TOCTOU race.

Changes

  • engine.py: Replaced exists()+open() with open() wrapped in try/except FileNotFoundError

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Removes the TOCTOU race when loading persisted workflow state.

Changes:

  • Opens state.json directly.
  • Converts missing-file failures into the existing domain-specific error.
Show a summary per file
File Description
src/specify_cli/workflows/engine.py Replaces exists() followed by open() with exception-based handling.

Review details

Tip

Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

  • Files reviewed: 1/1 changed files
  • Comments generated: 1
  • Review effort level: Medium

state_path = runs_dir / "state.json"
if not state_path.exists():

try:
Remove exists() check before open() and catch FileNotFoundError directly.
This prevents a race where the file is deleted between check and open,
while preserving the descriptive error message.
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.

3 participants