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

Open
opened 2026-11-26 20:18:37 +01:00 by 4ld0 · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ubiquitarianism/leonida/pull/616
Author: @hamdog0203
Created: 11/24/2026
Status: 🔄 Open

Base: main ← Head: fix/exe-sha-validate


📝 Commits (1)

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

📊 Changes

2 files changed (+74 additions, -9 deletions)

View changed files

📝 tests/test_exe_sha.py (+48 -0)
📝 tools/exe_sha.py (+26 -9)

📄 Description

Claimed in the coordination issue as: EXE-SHA-VALIDATE (https://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7128088818)
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.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/ubiquitarianism/leonida/pull/616 **Author:** [@hamdog0203](https://github.com/hamdog0203) **Created:** 11/24/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `fix/exe-sha-validate` --- ### 📝 Commits (1) - [`c09daf1`](https://github.com/ubiquitarianism/leonida/commit/c09daf1f66255c56948d65b1591593dfa77cf0f9) exe_sha: validate 64-hex SHA-256, reject bool size, and fail on unreadable --manifest (EXE-SHA-VALIDATE) ### 📊 Changes **2 files changed** (+74 additions, -9 deletions) <details> <summary>View changed files</summary> 📝 `tests/test_exe_sha.py` (+48 -0) 📝 `tools/exe_sha.py` (+26 -9) </details> ### 📄 Description Claimed in the coordination issue as: EXE-SHA-VALIDATE (https://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7128088818) 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. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
Sign in to join this conversation.
No labels
bug
pull-request
No milestone
No project
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.

Dependencies

No dependencies set

Reference
starred/leonida#657
No description provided.