fix(sync): load source once in sync_apply, pass to sync_check to close TOCTOU window#218
fix(sync): load source once in sync_apply, pass to sync_check to close TOCTOU window#218Tet-9 wants to merge 1 commit into
Conversation
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
8cc35b3 to
dffebd5
Compare
|
@plind-junior , review this when you are chanced |
|
@codex review |
|
Codex Review: Didn't find any major issues. Can't wait for the next one! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
|
@plind-junior , you may review this now as well |
Fixes #217
What
sync_applycalled_load_source(source_path)directly and then passedsource_pathintosync_check, which called_load_sourcea second timeinternally. This meant the validation and write phases operated on two
separate
_SyncSourceinstances.For bundle sources this opened a TOCTOU window: a bundle replaced on disk
between the two
_load_sourcecalls would passsync_check(validatingthe first snapshot) but write from the second, unvalidated load. It also
caused redundant I/O: directory sources were walked twice and bundle
tarballs were opened three times per
sync_applycall.Fix
sync_checknow accepts an optional_src: _SyncSource | None = Noneparameter. When supplied, it skips
_load_sourceand uses thepre-loaded instance directly.
sync_applyloads the source once and passes it intosync_checkvia_src=src, so both the check and write phases share the same validatedsnapshot.
Tests added
test_sync_apply_loads_source_exactly_once_for_kb— asserts_load_sourceis called exactly once duringsync_applyfor a KBdirectory source.
test_sync_apply_loads_bundle_source_exactly_once— same assertion fora bundle source.
test_sync_check_accepts_preloaded_src— assertssync_checkuses apre-loaded
_SyncSourcewhen supplied via_src.Checklist
make checkpasses (ruff + mypy + pytest, 554 passed)CHANGELOG.mdupdated under[Unreleased]testbranch