[PR #1866] tools/compute_heap_layout_census: validate fspx user_sgprs, strip BOM logs, extract testable main #1876

Open
opened 2026-11-26 21:19:15 +01:00 by 4ld0 · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ubiquitarianism/leonida/pull/1866
Author: @kirigayakazima
Created: 11/25/2026
Status: 🔄 Open

Base: main ← Head: fix/compute-heap-layout-safety


📝 Commits (1)

  • a51fba9 Harden compute_heap_layout_census BOM, fspx validation, and CLI error handling

📊 Changes

2 files changed (+117 additions, -7 deletions)

View changed files

📝 tests/test_compute_heap_layout_census.py (+87 -0)
📝 tools/compute_heap_layout_census.py (+30 -7)

📄 Description

Claimed in the coordination issue as: COMPUTE-HEAP-LAYOUT-BOM-FSPX-AND-DISPATCH-LOG-SAFETY (https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7164101436)

What and why

  • Open dispatch logs with encoding="utf-8-sig", errors="replace" in captured_layouts() (tools/compute_heap_layout_census.py) so UTF-8 BOM headers do not corrupt line 1.
  • Replace launch.exists() + unchecked json.loads(launch.read_bytes()) in program_loads() with launch.is_file(), explicit utf-8-sig decoding, path-attributed ValueError diagnostics for invalid UTF-8 / JSON / RecursionError / non-object roots, and strict type(raw_user) is int and raw_user >= 0 checking for user_sgprs (rejecting bool, str, and negative integers).
  • Extract main(argv=None) -> int catching (OSError, ValueError, KeyError, TypeError, RecursionError) to print ERROR: <exc> to stderr and return 2, with sys.stdout.reconfigure(errors="replace") under __main__.
  • Expand tests/test_compute_heap_layout_census.py with tests for BOM fspx/<name>.json fallback, directory at launch path, invalid UTF-8/JSON/type/range inputs, and BOM dispatch logs through main().

Tested

  • Patched: python -I tests/test_compute_heap_layout_census.py -v -> Ran 5 tests in 0.102s (OK).
  • Baseline check (upstream/main 5e95fa2f with updated test file copied into detached worktree): Ran 5 tests in 0.106s (FAILED (failures=3, errors=4)).
  • Repo gates: python -I tests/test_ci_registration.py (Ran 16 tests in 4.618s, OK), python -I tests/test_text_write_line_endings.py (Ran 3 tests in 12.681s, OK), python -I scripts/check_no_game_data.py (exit 0), python -I -m compileall -q (exit 0), git diff --check (exit 0).

GPUs tested: n/a (synthetic containers, listings, dispatch logs, and CLI error validation)

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.

🔄 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/1866 **Author:** [@kirigayakazima](https://github.com/kirigayakazima) **Created:** 11/25/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `fix/compute-heap-layout-safety` --- ### 📝 Commits (1) - [`a51fba9`](https://github.com/ubiquitarianism/leonida/commit/a51fba92172835195d70c42dd9d208caf15d4254) Harden compute_heap_layout_census BOM, fspx validation, and CLI error handling ### 📊 Changes **2 files changed** (+117 additions, -7 deletions) <details> <summary>View changed files</summary> 📝 `tests/test_compute_heap_layout_census.py` (+87 -0) 📝 `tools/compute_heap_layout_census.py` (+30 -7) </details> ### 📄 Description Claimed in the coordination issue as: COMPUTE-HEAP-LAYOUT-BOM-FSPX-AND-DISPATCH-LOG-SAFETY (https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7164101436) ### What and why - Open dispatch logs with `encoding="utf-8-sig", errors="replace"` in `captured_layouts()` (`tools/compute_heap_layout_census.py`) so UTF-8 BOM headers do not corrupt line 1. - Replace `launch.exists()` + unchecked `json.loads(launch.read_bytes())` in `program_loads()` with `launch.is_file()`, explicit `utf-8-sig` decoding, path-attributed `ValueError` diagnostics for invalid UTF-8 / JSON / `RecursionError` / non-object roots, and strict `type(raw_user) is int and raw_user >= 0` checking for `user_sgprs` (rejecting `bool`, `str`, and negative integers). - Extract `main(argv=None) -> int` catching `(OSError, ValueError, KeyError, TypeError, RecursionError)` to print `ERROR: <exc>` to `stderr` and return `2`, with `sys.stdout.reconfigure(errors="replace")` under `__main__`. - Expand `tests/test_compute_heap_layout_census.py` with tests for BOM `fspx/<name>.json` fallback, directory at launch path, invalid UTF-8/JSON/type/range inputs, and BOM dispatch logs through `main()`. ### Tested - Patched: `python -I tests/test_compute_heap_layout_census.py -v` -> `Ran 5 tests in 0.102s` (`OK`). - Baseline check (`upstream/main` `5e95fa2f` with updated test file copied into detached worktree): `Ran 5 tests in 0.106s` (`FAILED (failures=3, errors=4)`). - Repo gates: `python -I tests/test_ci_registration.py` (`Ran 16 tests in 4.618s`, `OK`), `python -I tests/test_text_write_line_endings.py` (`Ran 3 tests in 12.681s`, `OK`), `python -I scripts/check_no_game_data.py` (exit 0), `python -I -m compileall -q` (exit 0), `git diff --check` (exit 0). GPUs tested: n/a (synthetic containers, listings, dispatch logs, and CLI error validation) 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. --- <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#1876
No description provided.