Skip to content

Commit e80c541

Browse files
fix: eliminate TOCTOU races in catalog_fetch() for file:// and bare path URLs
Remove exists() pre-checks and catch FileNotFoundError from read_text() to provide clear BundlerError messages even under race conditions.
1 parent c3bbcc4 commit e80c541

1 file changed

Lines changed: 8 additions & 6 deletions

File tree

src/specify_cli/bundler/services/adapters.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -143,15 +143,17 @@ def fetch(source: CatalogSource) -> dict:
143143

144144
if scheme == "file":
145145
path = _file_url_to_path(parsed)
146-
if not path.exists():
147-
raise BundlerError(f"Catalog file not found: {path}")
148-
return load_json(path)
146+
try:
147+
return loads_json(path.read_text(encoding="utf-8"), origin=str(path))
148+
except FileNotFoundError:
149+
raise BundlerError(f"Catalog file not found: {path}") from None
149150

150151
if scheme == "" or _is_windows_drive_path(url):
151152
path = Path(url)
152-
if not path.exists():
153-
raise BundlerError(f"Catalog file not found: {path}")
154-
return load_json(path)
153+
try:
154+
return loads_json(path.read_text(encoding="utf-8"), origin=str(path))
155+
except FileNotFoundError:
156+
raise BundlerError(f"Catalog file not found: {path}") from None
155157

156158
if scheme in ("http", "https"):
157159
if not allow_network:

0 commit comments

Comments
 (0)