exe_sha: validate 64-hex SHA-256, reject bool size, and fail on unreadable --manifest (EXE-SHA-VALIDATE) #616

Open
github-bot wants to merge 1 commit from github-bot/gh-616 into main AGit
Owner

@⁠hamdog0203 on GitHub · 2026-11-24 10:00 UTC · original
hamdog0203:fix/exe-sha-validate → main · +74 −9 · 2 files · 1 commits · open

Claimed in the coordination issue as: EXE-SHA-VALIDATE (#14)
Depends on: none

What and why

Fixes four validation gaps in tools/exe_sha.py:

  • check() and recorded() only checked len == 64 for SHA-256 digests, so 64 non-hex characters (e.g. "z" * 64) bypassed the format check, hashed the entire file, and reported a hash mismatch instead of "is not a SHA-256 (64 hex digits)". recorded() also didn't strip surrounding whitespace.
  • recorded() accepted bool for expected_exe_size (isinstance(True, int) is True in Python).
  • A size-only manifest match left result["status"] as "unrecorded" instead of "match".
  • Passing a missing, malformed, or non-object JSON file via explicit --manifest silently fell back to unrecorded (exit 0) instead of exiting 2, and UTF-8 BOM manifests were rejected by json.load.

The fix

  • Added _valid_sha256() (strip + lowercase + 64 hex-digit check) and used it in both recorded() and check().
  • Rejected bool in recorded() (not isinstance(size, bool)), switched manifest reads in find_manifest() and recorded() to encoding="utf-8-sig", and added strict=(manifest is not None) so explicit --manifest errors propagate to main() and exit 2.
  • Marked size-only manifest matches as status = "match" in check().
  • Left if __name__ == "__main__": untouched to avoid conflicting with #605.
  • Added 5 regression tests in tests/test_exe_sha.py.

Tested

Windows 11 (26200.9974), Python 3.12.10, CPU only, no game files.

  • python -I tests/test_exe_sha.py -v: 16/16 OK
  • Negative control (the 5 new tests against main 21625bca8's tools/exe_sha.py): FAILED (failures=5)
  • python -m compileall -q tools/exe_sha.py tests/test_exe_sha.py: exit 0
  • python -I scripts/check_no_game_data.py tools/exe_sha.py tests/test_exe_sha.py: exit 0
  • python -I tests/test_text_write_line_endings.py: 3/3 OK
  • git diff --check: clean

AI-assisted: yes.

**@⁠hamdog0203** on GitHub · 2026-11-24 10:00 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/616) `hamdog0203:fix/exe-sha-validate` → `main` · +74 −9 · 2 files · 1 commits · open Claimed in the coordination issue as: EXE-SHA-VALIDATE (https://git.gtahub.st/github/ubiquitarianism--leonida/issues/14) Depends on: none ### What and why Fixes four validation gaps in `tools/exe_sha.py`: - `check()` and `recorded()` only checked `len == 64` for SHA-256 digests, so 64 non-hex characters (e.g. `"z" * 64`) bypassed the format check, hashed the entire file, and reported a hash mismatch instead of `"is not a SHA-256 (64 hex digits)"`. `recorded()` also didn't strip surrounding whitespace. - `recorded()` accepted `bool` for `expected_exe_size` (`isinstance(True, int)` is `True` in Python). - A size-only manifest match left `result["status"]` as `"unrecorded"` instead of `"match"`. - Passing a missing, malformed, or non-object JSON file via explicit `--manifest` silently fell back to `unrecorded` (`exit 0`) instead of exiting `2`, and UTF-8 BOM manifests were rejected by `json.load`. ### The fix - Added `_valid_sha256()` (strip + lowercase + 64 hex-digit check) and used it in both `recorded()` and `check()`. - Rejected `bool` in `recorded()` (`not isinstance(size, bool)`), switched manifest reads in `find_manifest()` and `recorded()` to `encoding="utf-8-sig"`, and added `strict=(manifest is not None)` so explicit `--manifest` errors propagate to `main()` and exit `2`. - Marked size-only manifest matches as `status = "match"` in `check()`. - Left `if __name__ == "__main__":` untouched to avoid conflicting with #605. - Added 5 regression tests in `tests/test_exe_sha.py`. ### Tested Windows 11 (26200.9974), Python 3.12.10, CPU only, no game files. - `python -I tests/test_exe_sha.py -v`: **16/16 OK** - Negative control (the 5 new tests against `main` `21625bca8`'s `tools/exe_sha.py`): **FAILED (failures=5)** - `python -m compileall -q tools/exe_sha.py tests/test_exe_sha.py`: exit 0 - `python -I scripts/check_no_game_data.py tools/exe_sha.py tests/test_exe_sha.py`: exit 0 - `python -I tests/test_text_write_line_endings.py`: **3/3 OK** - `git diff --check`: clean AI-assisted: yes.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 09:11:58 +00:00
Author
Owner

@⁠madvillain91 on GitHub · 2026-11-24 10:30 UTC · original · reviewed

Tested locally on Windows 11 — all 16 tests in \ ests/test_exe_sha.py\ pass. The _valid_sha256()\ helper, \ool\ size guard, \utf-8-sig\ BOM handling, and strict --manifest\ error path all look clean. LGTM.

**@⁠madvillain91** on GitHub · 2026-11-24 10:30 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/616#pullrequestreview-6037582953) · **reviewed** Tested locally on Windows 11 — all 16 tests in \ ests/test_exe_sha.py\ pass. The \_valid_sha256()\ helper, \ool\ size guard, \utf-8-sig\ BOM handling, and strict \--manifest\ error path all look clean. LGTM.
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/616/head:github-bot/gh-616'
git switch 'github-bot/gh-616'

Merge

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