fix: eliminate TOCTOU races in catalog_fetch() - #3910
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Eliminates TOCTOU races when reading local catalogs.
Changes:
- Removes
exists()pre-checks. - Converts
FileNotFoundErrorintoBundlerError.
Show a summary per file
| File | Description |
|---|---|
src/specify_cli/bundler/services/adapters.py |
Safely handles disappearing local catalog files. |
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: 1
- Review effort level: Balanced
mnriem
requested changes
Aug 10, 2026
mnriem
left a comment
Collaborator
There was a problem hiding this comment.
Please address Copilot feedback
Quratulain-bilal
force-pushed
the
fix/catalog-fetch-toctou
branch
from
August 10, 2026 21:24
9c1819d to
09a8ed5
Compare
Contributor
There was a problem hiding this comment.
Review details
Suppressed comments (1)
tests/unit/test_bundler_adapters.py:228
- The test never verifies the stated removal of the
exists()pre-check: an implementation that callsexists()and then catchesFileNotFoundErrorfromread_text()still passes. Assert thatexists()was not called so this regression test actually guards the PR's TOCTOU fix.
with patch.object(adapters.Path, "__new__", return_value=mock_path):
with pytest.raises(BundlerError, match="Catalog file not found"):
fetcher(_source(url))
- Files reviewed: 2/2 changed files
- Comments generated: 2
- Review effort level: Balanced
Collaborator
|
Please address Copilot feedback |
Contributor
Author
|
Hi @mnriem — I've addressed Copilot's feedback: removed the unused exists() mock setup and added mock_path.exists.assert_not_called() as a regression guard to verify the pre-check was genuinely eliminated. All 20 tests pass. Ready for re-review when you get a chance. |
…ath URLs Remove exists() pre-checks and catch FileNotFoundError from read_text() for both file:// and bare path catalog sources. Also catches OSError/UnicodeError to preserve the decode-error wrapping contract. Add regression test for the TOCTOU fix covering both file:// URLs and bare paths: the mocked Path raises FileNotFoundError from read_text(), proving the exists() removal eliminates the race window, with assert_not_called() as a regression guard that no pre-check remains.
Quratulain-bilal
force-pushed
the
fix/catalog-fetch-toctou
branch
from
September 23, 2026 17:40
42d5bfd to
2e56e69
Compare
mnriem
self-requested a review
September 24, 2026 11:34
mnriem
approved these changes
Sep 24, 2026
Collaborator
|
Thank you! |
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
catalog_fetch()checksexists()then callsread_text()for bothfile://and bare path URLs. The file can be deleted between the two calls.Fix
Remove the
exists()pre-checks and catchFileNotFoundErrorfromread_text().Testing
BundlerErroris raised when catalog file is missing