merge_check: guard ref option injection, bounds, and git timeouts #2334

Merged
leonida/mandy
kirigayakazima merged 3 commits from fix/merge-check-safety into main 2026-12-01 11:57:51 +00:00

Pull request successfully merged and closed

kirigayakazima commented 2026-11-26 14:01:26 +00:00

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

  • Add _validate_ref() in scripts/merge_check.py to reject empty, padded, or hyphen-prefixed git refs in --main and PR=REF (blocking git CLI option injection such as 12=--all or --main=--exec=...).
  • Validate PR numbers cleanly in parse_pair() (>= 1 ASCII integer with at most one leading #, rejecting 0=main and ##12=main) and add _positive_int (--depth >= 1) and _nonnegative_int (--min-length >= 0) bounds validators.
  • Add GIT_TIMEOUT = 120 in git(), converting subprocess.TimeoutExpired into GitError so hung git invocations return clean exit code 2 with a merge_check: diagnostic.
  • Add standard-library unit tests in tests/test_merge_check_safety.py.

Tested

  • python -I tests/test_merge_check_safety.py -v: 2 passed, 0 failed (detached upstream/main baseline 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, and git diff --cached --check: passed.

GPUs tested: n/a

AI-assisted: yes

Checklist

  • Based on current main and merges cleanly (a conflicting pull request is labeled needs rebase).
  • One topic; follow-up work goes in a new pull request.
  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed.
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 - Add `_validate_ref()` in `scripts/merge_check.py` to reject empty, padded, or hyphen-prefixed git refs in `--main` and `PR=REF` (blocking git CLI option injection such as `12=--all` or `--main=--exec=...`). - Validate PR numbers cleanly in `parse_pair()` (`>= 1` ASCII integer with at most one leading `#`, rejecting `0=main` and `##12=main`) and add `_positive_int` (`--depth >= 1`) and `_nonnegative_int` (`--min-length >= 0`) bounds validators. - Add `GIT_TIMEOUT = 120` in `git()`, converting `subprocess.TimeoutExpired` into `GitError` so hung git invocations return clean exit code `2` with a `merge_check:` diagnostic. - Add standard-library unit tests in `tests/test_merge_check_safety.py`. ### Tested - `python -I tests/test_merge_check_safety.py -v`: 2 passed, 0 failed (detached `upstream/main` baseline 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`, and `git diff --cached --check`: passed. GPUs tested: n/a AI-assisted: yes ### Checklist - [x] Based on current `main` and merges cleanly (a conflicting pull request is labeled `needs rebase`). - [x] One topic; follow-up work goes in a new pull request. - [x] No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here. - [ ] A new translator rule is in the contract table of `docs/design.md`, with how it was confirmed.
EdenBendheim commented 2026-11-26 21:43:43 +00:00

One boundary mismatch from local verification of d6bb80df4 against main at fac8b4bb9:

  • --min-length 0 mismatch: The claim in #1608 specifies rejecting nonpositive --min-length values, whereas scripts/merge_check.py:226 uses _nonnegative_int (accepting 0, which lets 1-character lines count toward duplicate blocks) and tests/test_merge_check_safety.py tests -1 without testing 0. Please either reject 0 (positive int) or update the claim/docs if 0 is intentional, and add a test covering 0.

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, and compileall all passed.

Synthetic fixtures only; no game data. GPUs tested: N/A (CPU-only). AI-assisted review.

One boundary mismatch from local verification of `d6bb80df4` against `main` at `fac8b4bb9`: - **`--min-length 0` mismatch:** The claim in #1608 specifies rejecting nonpositive `--min-length` values, whereas `scripts/merge_check.py:226` uses `_nonnegative_int` (accepting `0`, which lets 1-character lines count toward duplicate blocks) and `tests/test_merge_check_safety.py` tests `-1` without testing `0`. Please either reject `0` (positive int) or update the claim/docs if `0` is intentional, and add a test covering `0`. 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`, and `compileall` all passed. Synthetic fixtures only; no game data. GPUs tested: N/A (CPU-only). AI-assisted review.
tiguan26 approved these changes 2026-11-27 04:42:47 +00:00
tiguan26 left a comment

Approving d6bb80df4.

A --main or 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/--depth reject negative or zero values, and every git call now has a timeout that becomes a GitError.

Merged onto main d1dff7949 in 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).

Approving d6bb80df4. A `--main` or 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`/`--depth` reject negative or zero values, and every git call now has a timeout that becomes a `GitError`. Merged onto `main` `d1dff7949` in 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).
kirigayakazima commented 2026-11-27 12:02:43 +00:00

Thanks @EdenBendheim — updated --min-length to use _positive_int so 0 is rejected cleanly matching the #1608 claim, and added --min-length 0 coverage in tests/test_merge_check_safety.py. test_merge_check_safety.py (2 passed), test_merge_check.py (24 passed), and the 5 repository checks pass.

Thanks @EdenBendheim — updated `--min-length` to use `_positive_int` so `0` is rejected cleanly matching the `#1608` claim, and added `--min-length 0` coverage in `tests/test_merge_check_safety.py`. `test_merge_check_safety.py` (2 passed), `test_merge_check.py` (24 passed), and the 5 repository checks pass.
MoonEyes commented 2026-11-28 11:23:18 +00:00

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 rerun tests/test_merge_check_safety.py?

AI-assisted check (Claude Code, Claude Opus 5.5), posted for MoonEyes.

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 rerun `tests/test_merge_check_safety.py`? _AI-assisted check (Claude Code, Claude Opus 5.5), posted for MoonEyes._
TheGeogeo commented 2026-11-29 04:50:23 +00:00

Checked bf41c1699 against main ef3299584 on Windows 11 10.0.26300: it does not merge (git merge-tree --write-tree), so I ran no tests.

  • Conflict: scripts/merge_check.py, the git() signature. ead43b578 (2026-11-26, "merge_check: distinguish legacy-encoded lines before reporting duplicates") added stdout_errors="replace", where this PR adds timeout=GIT_TIMEOUT.
  • Still needed (STALE, needs a rebase). main has no _validate_ref, GIT_TIMEOUT or _positive_int, and no tests/test_merge_check_safety.py. The rebase looks mechanical: keep both parameters.

AI-assisted (Claude Code).

Checked `bf41c1699` against `main` `ef3299584` on Windows 11 10.0.26300: it does not merge (`git merge-tree --write-tree`), so I ran no tests. - Conflict: `scripts/merge_check.py`, the `git()` signature. `ead43b578` (2026-11-26, "merge_check: distinguish legacy-encoded lines before reporting duplicates") added `stdout_errors="replace"`, where this PR adds `timeout=GIT_TIMEOUT`. - Still needed (STALE, needs a rebase). `main` has no `_validate_ref`, `GIT_TIMEOUT` or `_positive_int`, and no `tests/test_merge_check_safety.py`. The rebase looks mechanical: keep both parameters. AI-assisted (Claude Code).
KelboLive commented 2026-11-30 17:34:48 +00:00

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).

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).
kirigayakazima commented 2026-12-01 11:15:26 +00:00

Merged upstream/main (3ee508b46) into this branch at f613e6d8e (no rebase, no force-push), resolving the scripts/merge_check.py git() conflict by keeping both stdout_errors="replace" from main and timeout=GIT_TIMEOUT / subprocess.TimeoutExpired from 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 OK
  • python -I tests/test_merge_check.py: 25 tests OK
  • python -I tests/test_text_write_line_endings.py: 3 tests OK
  • python -I scripts/check_no_game_data.py & git diff --check upstream/main...HEAD: clean (exit 0)

AI-assisted.

Merged `upstream/main` (`3ee508b46`) into this branch at `f613e6d8e` (no rebase, no force-push), resolving the `scripts/merge_check.py` `git()` conflict by keeping both `stdout_errors="replace"` from `main` and `timeout=GIT_TIMEOUT` / `subprocess.TimeoutExpired` from 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 OK** - `python -I tests/test_merge_check.py`: **25 tests OK** - `python -I tests/test_text_write_line_endings.py`: **3 tests OK** - `python -I scripts/check_no_game_data.py` & `git diff --check upstream/main...HEAD`: clean (exit 0) AI-assisted.
aslan2142 approved these changes 2026-12-01 11:33:14 +00:00
aslan2142 left a comment

Reviewed the diff against main: scripts/merge_check.py:17-68 cleanly adds GIT_TIMEOUT = 120 with TimeoutExpired -> GitError, validates --min-length/--depth as positive integers, and rejects blank, padded, or --prefixed refs via _validate_ref (blocking option injection) alongside unit tests in tests/test_merge_check_safety.py. Clean-room verified. Approving; awaiting completion of the in-progress windows CI check before merge.

(AI-assisted review.)

Reviewed the diff against `main`: `scripts/merge_check.py:17-68` cleanly adds `GIT_TIMEOUT = 120` with `TimeoutExpired -> GitError`, validates `--min-length`/`--depth` as positive integers, and rejects blank, padded, or `-`-prefixed refs via `_validate_ref` (blocking option injection) alongside unit tests in `tests/test_merge_check_safety.py`. Clean-room verified. Approving; awaiting completion of the in-progress `windows` CI check before merge. *(AI-assisted review.)*
Sign in to join this conversation.
No description provided.