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

Merged
kirigayakazima merged 3 commits from upstream-pr/2334 into main 2026-12-01 11:57:51 +00:00
kirigayakazima commented 2026-11-26 14:01:26 +00:00 (Migrated from github.com)

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

  • 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.
<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5511407768 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2334). Originally posted by [kirigayakazima](https://github.com/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 - 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 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by EdenBendheim on 2026-11-26T21:43:43Z.


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.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7204003003 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/2334#issuecomment-7204003003). Originally posted by [EdenBendheim](https://github.com/EdenBendheim) on 2026-11-26T21:43:43Z. --- 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 commented 2026-11-27 04:42:47 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by tiguan26 on 2026-11-27T04:42:47Z.

Review: APPROVED


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

<!-- greyfinch-sync:ubiquitarianism/leonida:review:6083578137 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2334#pullrequestreview-6083578137). Originally posted by [tiguan26](https://github.com/tiguan26) on 2026-11-27T04:42:47Z. **Review:** APPROVED --- 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 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by kirigayakazima on 2026-11-27T12:02:43Z.


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.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7217772862 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/2334#issuecomment-7217772862). Originally posted by [kirigayakazima](https://github.com/kirigayakazima) on 2026-11-27T12:02:43Z. --- 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 (Migrated from github.com)

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

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7238517405 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2334#issuecomment-7238517405). Originally posted by [MoonEyes](https://github.com/MoonEyes) on 2026-11-28T11:23:18Z. --- 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 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by TheGeogeo on 2026-11-29T04:50:23Z.


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

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7250892059 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2334#issuecomment-7250892059). Originally posted by [TheGeogeo](https://github.com/TheGeogeo) on 2026-11-29T04:50:23Z. --- 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 (Migrated from github.com)

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

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7286528897 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2334#issuecomment-7286528897). Originally posted by [KelboLive](https://github.com/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).
kirigayakazima commented 2026-12-01 11:15:26 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by kirigayakazima on 2026-12-01T11:15:26Z.


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.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7309388140 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2334#issuecomment-7309388140). Originally posted by [kirigayakazima](https://github.com/kirigayakazima) on 2026-12-01T11:15:26Z. --- 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 commented 2026-12-01 11:33:14 +00:00 (Migrated from github.com)

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

<!-- greyfinch-sync:ubiquitarianism/leonida:review:6130381568 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2334#pullrequestreview-6130381568). Originally posted by [aslan2142](https://github.com/aslan2142) on 2026-12-01T11:33:14Z. **Review:** APPROVED --- 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 reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
ProjectLeonida/mandy!2334
No description provided.