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

Open
github-bot wants to merge 2 commits from github-bot/gh-2334 into main AGit
Owner

@⁠kirigayakazima on GitHub · 2026-11-26 14:01 UTC · original
kirigayakazima:fix/merge-check-safety → main · +96 −7 · 2 files · 2 commits · open

Claimed in the coordination issue as: MERGE-CHECK-OPTION-INJECTION-BOUNDS-AND-GIT-TIMEOUT (#1608)

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.
**@⁠kirigayakazima** on GitHub · 2026-11-26 14:01 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/2334) `kirigayakazima:fix/merge-check-safety` → `main` · +96 −7 · 2 files · 2 commits · open Claimed in the coordination issue as: MERGE-CHECK-OPTION-INJECTION-BOUNDS-AND-GIT-TIMEOUT (https://git.gtahub.st/github/ubiquitarianism--leonida/issues/1608) ### 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.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 14:08:00 +00:00
Author
Owner

@⁠EdenBendheim on GitHub · 2026-11-26 21:43 UTC · original

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.

**@⁠EdenBendheim** on GitHub · 2026-11-26 21:43 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/2334#issuecomment-7204003003) 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.
Author
Owner

@⁠tiguan26 on GitHub · 2026-11-27 04:42 UTC · original · approved these changes

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

**@⁠tiguan26** on GitHub · 2026-11-27 04:42 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/2334#pullrequestreview-6083578137) · **approved these changes** 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).
Author
Owner

@⁠kirigayakazima on GitHub · 2026-11-27 12:02 UTC · original

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.

**@⁠kirigayakazima** on GitHub · 2026-11-27 12:02 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/2334#issuecomment-7217772862) 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.
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/2334/head:github-bot/gh-2334'
git switch 'github-bot/gh-2334'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-2334'
git switch 'github-bot/gh-2334'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-2334'
git switch 'github-bot/gh-2334'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-2334'
git switch 'main'
git merge --squash 'github-bot/gh-2334'
git switch 'main'
git merge --ff-only 'github-bot/gh-2334'
git switch 'main'
git merge 'github-bot/gh-2334'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.