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

Open
github-bot wants to merge 1 commit from github-bot/gh-1658 into main AGit
Owner

@⁠IlyassRS3 on GitHub · 2026-11-25 07:24 UTC · original
IlyassRS3:fix/fssm-unpack-io-and-bounds → main · +125 −17 · 2 files · 1 commits · open

Item ID: FSSM-UNPACK-IO-AND-BOUNDS
Claim: #1608

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)

**@⁠IlyassRS3** on GitHub · 2026-11-25 07:24 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1658) `IlyassRS3:fix/fssm-unpack-io-and-bounds` → `main` · +125 −17 · 2 files · 1 commits · open Item ID: `FSSM-UNPACK-IO-AND-BOUNDS` Claim: https://git.gtahub.st/github/ubiquitarianism--leonida/issues/1608 ## 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)
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 09:59:41 +00:00
Author
Owner

@⁠copilot-pull-request-reviewer[bot] on GitHub · 2026-11-25 07:24 UTC · original · reviewed

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.

**@⁠copilot-pull-request-reviewer[bot]** on GitHub · 2026-11-25 07:24 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1658#pullrequestreview-6053417125) · **reviewed** 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.
Author
Owner

@⁠whoalin1 on GitHub · 2026-11-25 08:04 UTC · original

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.

**@⁠whoalin1** on GitHub · 2026-11-25 08:04 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1658#issuecomment-7156574470) 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.
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/1658/head:github-bot/gh-1658'
git switch 'github-bot/gh-1658'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-1658'
git switch 'github-bot/gh-1658'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-1658'
git switch 'github-bot/gh-1658'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-1658'
git switch 'main'
git merge --squash 'github-bot/gh-1658'
git switch 'main'
git merge --ff-only 'github-bot/gh-1658'
git switch 'main'
git merge 'github-bot/gh-1658'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.