Skip to content

Commit 6042b2c

Browse files
fix: handle TOCTOU race in list_runs state file read
Remove exists() check and wrap open/load in try/except to handle the case where state.json is deleted between the check and open. A missing or corrupt state file now skips that run instead of crashing the entire list_runs operation.
1 parent be33d2a commit 6042b2c

1 file changed

Lines changed: 3 additions & 1 deletion

File tree

‎src/specify_cli/workflows/engine.py‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1582,10 +1582,12 @@ def list_runs(self) -> list[dict[str, Any]]:
15821582
if not run_dir.is_dir():
15831583
continue
15841584
state_path = run_dir / "state.json"
1585-
if state_path.exists():
1585+
try:
15861586
with open(state_path, encoding="utf-8") as f:
15871587
state_data = json.load(f)
15881588
runs.append(state_data)
1589+
except (FileNotFoundError, json.JSONDecodeError, OSError):
1590+
continue
15891591
return runs
15901592

15911593

0 commit comments

Comments
 (0)