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

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

📋 Pull Request Information

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

Base: main ← Head: fix/fssm-unpack-io-and-bounds


📝 Commits (1)

  • 9231063 fssm_unpack: validate DXBC magic and 24-byte XBCH header, guard empty --carve-index and write errors, and preserve index symlinks/mode

📊 Changes

2 files changed (+125 additions, -17 deletions)

View changed files

📝 tests/test_fssm_unpack.py (+78 -0)
📝 tools/fssm_unpack.py (+47 -17)

📄 Description

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)


🔄 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/1658 **Author:** [@IlyassRS3](https://github.com/IlyassRS3) **Created:** 11/25/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `fix/fssm-unpack-io-and-bounds` --- ### 📝 Commits (1) - [`9231063`](https://github.com/ubiquitarianism/leonida/commit/9231063348ad2c6ab963349381a654f9e77fdade) fssm_unpack: validate DXBC magic and 24-byte XBCH header, guard empty --carve-index and write errors, and preserve index symlinks/mode ### 📊 Changes **2 files changed** (+125 additions, -17 deletions) <details> <summary>View changed files</summary> 📝 `tests/test_fssm_unpack.py` (+78 -0) 📝 `tools/fssm_unpack.py` (+47 -17) </details> ### 📄 Description 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) --- <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#1672
No description provided.