merge_check: guard ref option injection, bounds, and git timeouts #2334
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2334"
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?
Imported from ubiquitarianism/leonida. Originally posted by kirigayakazima on 2026-11-26T14:01:26Z.
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.Imported from ubiquitarianism/leonida. Originally posted by EdenBendheim on 2026-11-26T21:43:43Z.
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.
Imported from ubiquitarianism/leonida. Originally posted by tiguan26 on 2026-11-27T04:42:47Z.
Review: APPROVED
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).Imported from ubiquitarianism/leonida. Originally posted by kirigayakazima on 2026-11-27T12:02:43Z.
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.Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-11-28T11:23:18Z.
Blocker: this branch (head
bf41c1699) no longer merges into current main (4a54aedcb): content conflict inscripts/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.
Imported from ubiquitarianism/leonida. Originally posted by TheGeogeo on 2026-11-29T04:50:23Z.
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).
Imported from ubiquitarianism/leonida. Originally posted by KelboLive on 2026-11-30T17:34:48Z.
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).
Imported from ubiquitarianism/leonida. Originally posted by kirigayakazima on 2026-12-01T11:15:26Z.
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.
Imported from ubiquitarianism/leonida. Originally posted by aslan2142 on 2026-12-01T11:33:14Z.
Review: APPROVED
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.)