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

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

📋 Pull Request Information

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

Base: main ← Head: fix/sgd5-effects-boundary-validation


📝 Commits (1)

  • 1bdf2bf sgd5_effects: enforce database bounds in program_groups, guard program_identity EOF, validate layout

📊 Changes

2 files changed (+69 additions, -4 deletions)

View changed files

📝 tests/test_sgd5_effects.py (+41 -0)
📝 tools/sgd5_effects.py (+28 -4)

📄 Description

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)


🔄 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/1589 **Author:** [@IlyassRS3](https://github.com/IlyassRS3) **Created:** 11/25/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `fix/sgd5-effects-boundary-validation` --- ### 📝 Commits (1) - [`1bdf2bf`](https://github.com/ubiquitarianism/leonida/commit/1bdf2bf56c6604b02de6f2b74ef5c673843f418e) sgd5_effects: enforce database bounds in program_groups, guard program_identity EOF, validate layout ### 📊 Changes **2 files changed** (+69 additions, -4 deletions) <details> <summary>View changed files</summary> 📝 `tests/test_sgd5_effects.py` (+41 -0) 📝 `tools/sgd5_effects.py` (+28 -4) </details> ### 📄 Description 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) --- <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#1609
No description provided.