sgd5_effects: enforce database bounds in program_groups, guard program_identity EOF, validate layout (SGD5-EFFECTS-BOUNDARY-VALIDATION) #1589

Merged
IlyassRS3 merged 1 commit from upstream-pr/1589 into main 2026-11-28 10:27:01 +00:00
IlyassRS3 commented 2026-11-25 05:19:30 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by IlyassRS3 on 2026-11-25T05:19:30Z.


Item: SGD5-EFFECTS-BOUNDARY-VALIDATION (unclaimed — coordination issue #14 is at GitHub's 2,500-comment cap with no successor open issue yet, and 0 open PRs touch tools/sgd5_effects.py).

Summary

  • Enforce limit before every read in program_groups() (group count headers, per-group count upper bound against the 176-byte minimum program record size, program label/tag/size framing, and effect-count header in read_database()) so malformed records in database 1 never read past limit into following archive data.
  • Guard program_identity() against negative offsets, EOF, short length bytes (< 2), and truncated windows so it raises ValueError instead of crashing with IndexError on stream.read(1)[0] or window[pos - 1].
  • Validate layout ordering (0 <= database, first_group >= database + 4, end > first_group) up front in read_database(), and pass allow_nan=False to json.dumps() in main().

Verification

  • python3 -W error -I tests/test_sgd5_effects.py -v: 12 passed, 1 skipped (retail package test without LEONIDA_GAME_DIR).
  • python3 -I tests/test_text_write_line_endings.py: 3/3 passed.
  • python3 -I scripts/check_no_game_data.py tools/sgd5_effects.py tests/test_sgd5_effects.py: passed.
  • python3 -m compileall -q tools/sgd5_effects.py tests/test_sgd5_effects.py: passed.
  • Mutation check (running tests/test_sgd5_effects.py against unpatched main:tools/sgd5_effects.py): failures=7, errors=2 across all new regression tests.

AI-assisted: yes
GPUs tested: none (CPU-only Python binary metadata parser; synthetic SGD5 blobs only, no game data)

<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5485648708 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1589). Originally posted by [IlyassRS3](https://github.com/IlyassRS3) on 2026-11-25T05:19:30Z. --- Item: `SGD5-EFFECTS-BOUNDARY-VALIDATION` (unclaimed — coordination issue #14 is at GitHub's 2,500-comment cap with no successor open issue yet, and 0 open PRs touch `tools/sgd5_effects.py`). ### Summary - Enforce `limit` before every read in `program_groups()` (group count headers, per-group count upper bound against the 176-byte minimum program record size, program label/tag/size framing, and effect-count header in `read_database()`) so malformed records in database 1 never read past `limit` into following archive data. - Guard `program_identity()` against negative offsets, EOF, short length bytes (`< 2`), and truncated windows so it raises `ValueError` instead of crashing with `IndexError` on `stream.read(1)[0]` or `window[pos - 1]`. - Validate `layout` ordering (`0 <= database`, `first_group >= database + 4`, `end > first_group`) up front in `read_database()`, and pass `allow_nan=False` to `json.dumps()` in `main()`. ### Verification - `python3 -W error -I tests/test_sgd5_effects.py -v`: 12 passed, 1 skipped (retail package test without `LEONIDA_GAME_DIR`). - `python3 -I tests/test_text_write_line_endings.py`: 3/3 passed. - `python3 -I scripts/check_no_game_data.py tools/sgd5_effects.py tests/test_sgd5_effects.py`: passed. - `python3 -m compileall -q tools/sgd5_effects.py tests/test_sgd5_effects.py`: passed. - Mutation check (running `tests/test_sgd5_effects.py` against unpatched `main:tools/sgd5_effects.py`): `failures=7, errors=2` across all new regression tests. AI-assisted: yes GPUs tested: none (CPU-only Python binary metadata parser; synthetic SGD5 blobs only, no game data)
copilot-pull-request-reviewer[bot] commented 2026-11-25 05:19:41 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by copilot-pull-request-reviewer[bot] on 2026-11-25T05:19:41Z.

Review: COMMENTED


Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

<!-- greyfinch-sync:ubiquitarianism/leonida:review:6052229800 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1589#pullrequestreview-6052229800). Originally posted by [copilot-pull-request-reviewer[bot]](https://github.com/apps/copilot-pull-request-reviewer) on 2026-11-25T05:19:41Z. **Review:** COMMENTED --- Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.
MoonEyes commented 2026-11-28 10:26:47 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-11-28T10:26:47Z.


Red/green: the PR's tests fail on main and pass with this PR (Linux, Python 3.13.18).
Targeted batch of 18 PRs (their tests, the tests importing the changed modules, the docs tests) on main 3ca0707: no new failure, Linux / Python 3.13.
AI-assisted (Claude Code, Claude Opus 5.5)

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7237901511 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1589#issuecomment-7237901511). Originally posted by [MoonEyes](https://github.com/MoonEyes) on 2026-11-28T10:26:47Z. --- Red/green: the PR's tests fail on main and pass with this PR (Linux, Python 3.13.18). Targeted batch of 18 PRs (their tests, the tests importing the changed modules, the docs tests) on main 3ca0707: no new failure, Linux / Python 3.13. AI-assisted (Claude Code, Claude Opus 5.5)
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!1589
No description provided.