fssm_unpack: validate DXBC magic and 24-byte XBCH header, guard empty --carve-index and write OSErrors, and preserve index symlinks/mode #1658

Merged
IlyassRS3 merged 1 commit from upstream-pr/1658 into main 2026-11-28 14:47:04 +00:00
IlyassRS3 commented 2026-11-25 07:24:08 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by IlyassRS3 on 2026-11-25T07:24:08Z.


Item ID: FSSM-UNPACK-IO-AND-BOUNDS
Claim: https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7155785517

Summary

  • Container/header validation (tools/fssm_unpack.py): validate b"DXBC" magic in parts() (previously any 32-byte blob with zeroed part count succeeded silently) and require the full 24-byte XBCH header in _inflate_xbch() (catching 20..23-byte truncated headers with struct.error).
  • Single-pass container parse: share _unpack_with_count() between unpack() and main() so main() no longer re-parses DXBC/XDAT twice per container.
  • CLI & I/O error handling: reject empty/whitespace --carve-index (previously falsy "" silently fell back to scanning the directory); fail upfront with exit 2 when fssm_index.json is a directory; catch OSError cleanly (exit 2, no traceback) when writing .fssm blobs or publishing fssm_index.json.
  • Atomic index publication: resolve symlinked fssm_index.json targets so the symlink is preserved, preserve target file mode via file_mode.published_mode(), and append a trailing newline.
  • Tests (tests/test_fssm_unpack.py): add 4 regression tests covering DXBC magic, 20/23-byte truncated XBCH headers, empty --carve-index, directory/write OSError paths, and symlink/mode preservation.

Verification

  • python3 -W error -I tests/test_fssm_unpack.py -v: 52 passed, 0 failed (1.022s).
  • python3 -I tests/test_replace_retry.py: 10 tests OK (2 skipped).
  • python3 -I tests/test_shader_stage_manifest.py: 17 tests OK.
  • python3 -I tests/test_fssm_crosscheck.py: 6 tests OK.
  • Mutation check against unpatched main: ran=52, failures=5, errors=0.
  • python3 -m compileall -q tools/fssm_unpack.py tests/test_fssm_unpack.py, python3 -I tests/test_text_write_line_endings.py, python3 -I scripts/check_no_game_data.py: all pass.

AI-assisted: yes
GPUs tested: none (CPU unit tests with synthetic DXBC/XBCH/FSSM bytes; no game data)

<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5487019635 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1658). Originally posted by [IlyassRS3](https://github.com/IlyassRS3) on 2026-11-25T07:24:08Z. --- Item ID: `FSSM-UNPACK-IO-AND-BOUNDS` Claim: https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7155785517 ## Summary - **Container/header validation (`tools/fssm_unpack.py`)**: validate `b"DXBC"` magic in `parts()` (previously any 32-byte blob with zeroed part count succeeded silently) and require the full 24-byte XBCH header in `_inflate_xbch()` (catching 20..23-byte truncated headers with `struct.error`). - **Single-pass container parse**: share `_unpack_with_count()` between `unpack()` and `main()` so `main()` no longer re-parses DXBC/XDAT twice per container. - **CLI & I/O error handling**: reject empty/whitespace `--carve-index` (previously falsy `""` silently fell back to scanning the directory); fail upfront with exit `2` when `fssm_index.json` is a directory; catch `OSError` cleanly (exit `2`, no traceback) when writing `.fssm` blobs or publishing `fssm_index.json`. - **Atomic index publication**: resolve symlinked `fssm_index.json` targets so the symlink is preserved, preserve target file mode via `file_mode.published_mode()`, and append a trailing newline. - **Tests (`tests/test_fssm_unpack.py`)**: add 4 regression tests covering DXBC magic, 20/23-byte truncated XBCH headers, empty `--carve-index`, directory/write `OSError` paths, and symlink/mode preservation. ## Verification - `python3 -W error -I tests/test_fssm_unpack.py -v`: **52 passed, 0 failed** (1.022s). - `python3 -I tests/test_replace_retry.py`: **10 tests OK (2 skipped)**. - `python3 -I tests/test_shader_stage_manifest.py`: **17 tests OK**. - `python3 -I tests/test_fssm_crosscheck.py`: **6 tests OK**. - Mutation check against unpatched `main`: **ran=52, failures=5, errors=0**. - `python3 -m compileall -q tools/fssm_unpack.py tests/test_fssm_unpack.py`, `python3 -I tests/test_text_write_line_endings.py`, `python3 -I scripts/check_no_game_data.py`: all pass. AI-assisted: yes GPUs tested: none (CPU unit tests with synthetic DXBC/XBCH/FSSM bytes; no game data)
copilot-pull-request-reviewer[bot] commented 2026-11-25 07:24:25 +00:00 (Migrated from github.com)

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

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:6053417125 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1658#pullrequestreview-6053417125). Originally posted by [copilot-pull-request-reviewer[bot]](https://github.com/apps/copilot-pull-request-reviewer) on 2026-11-25T07:24:25Z. **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.
whoalin1 commented 2026-11-25 08:04:25 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by whoalin1 on 2026-11-25T08:04:25Z.


Independent verification (native Windows, Python 3.11.9): diff vs merge-base reviewed — DXBC magic check, 24-byte XBCH header guard, shared _unpack_with_count, empty --carve-index rejection, index-publish symlink/realpath staging with published_mode+replace_retry all present. Tests: test_fssm_unpack.py 52 OK (1 skip), neighbors test_replace_retry 10, test_shader_stage_manifest 17, test_fssm_crosscheck 6, line-endings 3 — all pass; compileall, --help, check_no_game_data clean. AI-assisted verification.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7156574470 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/1658#issuecomment-7156574470). Originally posted by [whoalin1](https://github.com/whoalin1) on 2026-11-25T08:04:25Z. --- Independent verification (native Windows, Python 3.11.9): diff vs merge-base reviewed — DXBC magic check, 24-byte XBCH header guard, shared `_unpack_with_count`, empty `--carve-index` rejection, index-publish symlink/realpath staging with `published_mode`+`replace_retry` all present. Tests: `test_fssm_unpack.py` 52 OK (1 skip), neighbors `test_replace_retry` 10, `test_shader_stage_manifest` 17, `test_fssm_crosscheck` 6, line-endings 3 — all pass; compileall, `--help`, `check_no_game_data` clean. AI-assisted verification.
MoonEyes commented 2026-11-28 14:47:01 +00:00 (Migrated from github.com)

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


Red/green: pytest tests/test_fssm_unpack.py fails on main (4 failed, 49 passed, 1 skipped, 14 subtests passed) and passes on head 9231063348 merged with main (51 passed, 1 skipped, 18 subtests passed).
Targeted batch (PR tests, tests importing the changed modules, docs tests, translator when touched) merged on main d48a957bb in GitHub Actions: no new failure.
AI-assisted (Claude Code, Claude Opus 5.5)

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7240927406 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1658#issuecomment-7240927406). Originally posted by [MoonEyes](https://github.com/MoonEyes) on 2026-11-28T14:47:01Z. --- Red/green: `pytest tests/test_fssm_unpack.py` fails on main (4 failed, 49 passed, 1 skipped, 14 subtests passed) and passes on head 9231063348ad merged with main (51 passed, 1 skipped, 18 subtests passed). Targeted batch (PR tests, tests importing the changed modules, docs tests, translator when touched) merged on main d48a957bb in GitHub Actions: no new failure. 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!1658
No description provided.