merge_check: guard ref option injection, bounds, and git timeouts #2334
No assignees
Labels
No labels
bug
dependencies
documentation
enhancement
missing claim
needs rebase
needs-triage
question
ready-for-agent
submodules
No project
No milestone
Dependencies
No dependencies set
Notifications
1 participant
Due date
No due date set.
Reference
leonida/mandy!2334
Loading…
Reference in a new issue
No description provided.
Delete branch "fix/merge-check-safety"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Pull request successfully merged and closed
Claimed in the coordination issue as: MERGE-CHECK-OPTION-INJECTION-BOUNDS-AND-GIT-TIMEOUT (https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7194083451)
What and why
_validate_ref()inscripts/merge_check.pyto reject empty, padded, or hyphen-prefixed git refs in--mainandPR=REF(blocking git CLI option injection such as12=--allor--main=--exec=...).parse_pair()(>= 1ASCII integer with at most one leading#, rejecting0=mainand##12=main) and add_positive_int(--depth >= 1) and_nonnegative_int(--min-length >= 0) bounds validators.GIT_TIMEOUT = 120ingit(), convertingsubprocess.TimeoutExpiredintoGitErrorso hung git invocations return clean exit code2with amerge_check:diagnostic.tests/test_merge_check_safety.py.Tested
python -I tests/test_merge_check_safety.py -v: 2 passed, 0 failed (detachedupstream/mainbaseline with only the new test file fails with 9 subtest failures and 1 error).python -I tests/test_merge_check.py -v: 24 passed, 0 failed.python -I tests/test_ci_registration.py: 16 passed.python -I tests/test_text_write_line_endings.py: 3 passed.python -I scripts/check_no_game_data.py,python -I -m compileall -q scripts/merge_check.py tests/test_merge_check_safety.py, andgit diff --cached --check: passed.GPUs tested: n/a
AI-assisted: yes
Checklist
mainand merges cleanly (a conflicting pull request is labeledneeds rebase).docs/design.md, with how it was confirmed.One boundary mismatch from local verification of
d6bb80df4againstmainatfac8b4bb9:--min-length 0mismatch: The claim in #1608 specifies rejecting nonpositive--min-lengthvalues, whereasscripts/merge_check.py:226uses_nonnegative_int(accepting0, which lets 1-character lines count toward duplicate blocks) andtests/test_merge_check_safety.pytests-1without testing0. Please either reject0(positive int) or update the claim/docs if0is intentional, and add a test covering0.The leading-hyphen ref guard and per-command git timeout handling both look solid, and overlap with #2197 is minimal (different lines in the git helper).
Checks run on macOS 27.3 arm64 (Python 3.14.3): patch applies cleanly. On plain
main, the two new safety tests hit 9 subtest failures and 1 error; with the patch,test_merge_check_safety.py(2/2),test_merge_check.py(24/24),test_text_write_line_endings.py(3/3),check_no_game_data.py, andcompileallall passed.Synthetic fixtures only; no game data. GPUs tested: N/A (CPU-only). AI-assisted review.
Approving d6bb80df4.
A
--mainor target ref that starts with-(or is blank or padded) is refused before it can reach git as an option, the PR number must be ASCII digits and at least 1,--min-length/--depthreject negative or zero values, and every git call now has a timeout that becomes aGitError.Merged onto
maind1dff7949in one batch with 15 other tool PRs of this series (no conflicts), on Linux with Python 3.13.tests/test_merge_check_safety.py: 2 passed, 9 subtests (new). AI-assisted (Claude Code, Claude Opus 5.5).Thanks @EdenBendheim — updated
--min-lengthto use_positive_intso0is rejected cleanly matching the#1608claim, and added--min-length 0coverage intests/test_merge_check_safety.py.test_merge_check_safety.py(2 passed),test_merge_check.py(24 passed), and the 5 repository checks pass.Blocker: this branch (head bf41c1699) no longer merges into current main (4a54aedcb): content conflict in
scripts/merge_check.py. Could you merge main into the branch (no rebase or force-push), resolve it, and reruntests/test_merge_check_safety.py?AI-assisted check (Claude Code, Claude Opus 5.5), posted for MoonEyes.
Checked
bf41c1699againstmainef3299584on Windows 11 10.0.26300: it does not merge (git merge-tree --write-tree), so I ran no tests.scripts/merge_check.py, thegit()signature.ead43b578(2026-11-26, "merge_check: distinguish legacy-encoded lines before reporting duplicates") addedstdout_errors="replace", where this PR addstimeout=GIT_TIMEOUT.mainhas no_validate_ref,GIT_TIMEOUTor_positive_int, and notests/test_merge_check_safety.py. The rebase looks mechanical: keep both parameters.AI-assisted (Claude Code).
Independent check on Windows (not the author), at
bf41c1699.python -I tests/test_merge_check_safety.py: 2 tests OK.Environment: Windows 11 Pro 10.0.26200.9711, Python 3.12.10.
AI-assisted: yes (opencode).
Merged
upstream/main(3ee508b46) into this branch atf613e6d8e(no rebase, no force-push), resolving thescripts/merge_check.pygit()conflict by keeping bothstdout_errors="replace"frommainandtimeout=GIT_TIMEOUT/subprocess.TimeoutExpiredfrom this PR.Thanks @MoonEyes and @TheGeogeo for flagging the exact merge conflict.
Verification (Windows 11, Python 3.12, no game data)
python -I tests/test_merge_check_safety.py: 2 tests OKpython -I tests/test_merge_check.py: 25 tests OKpython -I tests/test_text_write_line_endings.py: 3 tests OKpython -I scripts/check_no_game_data.py&git diff --check upstream/main...HEAD: clean (exit 0)AI-assisted.
Reviewed the diff against
main:scripts/merge_check.py:17-68cleanly addsGIT_TIMEOUT = 120withTimeoutExpired -> GitError, validates--min-length/--depthas positive integers, and rejects blank, padded, or--prefixed refs via_validate_ref(blocking option injection) alongside unit tests intests/test_merge_check_safety.py. Clean-room verified. Approving; awaiting completion of the in-progresswindowsCI check before merge.(AI-assisted review.)