[PR #656] rpf9dump: harden segment bounds and CLI option validation (RPF9DUMP-SEGMENTS-AND-CLI) #695

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

📋 Pull Request Information

Original PR: https://github.com/ubiquitarianism/leonida/pull/656
Author: @kirigayakazima
Created: 11/24/2026
Status: 🔄 Open

Base: main ← Head: fix/rpf9dump-segments-and-cli


📝 Commits (1)

  • c28b21a rpf9dump: harden segment bounds and CLI option validation (RPF9DUMP-SEGMENTS-AND-CLI)

📊 Changes

4 files changed (+49 additions, -5 deletions)

View changed files

📝 tests/Rpf9DumpDiagnostics/Program.cs (+9 -0)
📝 tests/test_rpf9dump_exit_codes.py (+28 -0)
📝 tools/rpf9dump/Program.cs (+8 -4)
📝 tools/rpf9dump/Segments.cs (+4 -1)

📄 Description

Claimed in the coordination issue as: RPF9DUMP-SEGMENTS-AND-CLI (https://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7129604877)

What and why

Follow-up hardening to merged #6344 (now on main) across tools/rpf9dump/:

  • tools/rpf9dump/Segments.cs (RecoveredResource.Read):
    • Prevent Int64 overflow in block.Offset + block.StoredSize > file.Length by checking block.Offset > file.Length || block.StoredSize > file.Length - block.Offset (matching RecoveryIndexCache's subtraction guard). Previously, e.g. (Offset=32, StoredSize=long.MaxValue) wrapped negative, passed the bounds check, and read a valid compressed stream starting at offset 32.
    • Reject raw blocks where block.IsRaw && block.StoredSize != block.Size with InvalidDataException instead of copying a partial or mismatched slice.
  • tools/rpf9dump/Program.cs:
    • Check unknown CLI options (argv[i] is not ("--start" or "--length")) before validating the value argument so bare --bogus or --bogus notanumber reports Unknown option --bogus. rather than claiming it needs a non-negative byte count., and emit both diagnostics on Console.Error.
    • Parse --jobs with NumberStyles.None, CultureInfo.InvariantCulture (consistent with --start / --length) so +2 / whitespace / locale digits are rejected cleanly with exit code 2.
  • tests/Rpf9DumpDiagnostics/Program.cs & tests/test_rpf9dump_exit_codes.py:
    • Add diagnostics cases for overflowing StoredSize and mismatched raw-block StoredSize != Size (both > and <).
    • Add exit-code tests for unknown options and invalid/signed/non-positive --jobs values leaving output directories uncreated.

(Keeps tests/test_rpf9dump_exit_codes.py lines 87–120 untouched so this merges cleanly alongside #655.)

Tested

On Windows 11 x64 (.NET 8.0.401, Python 3.14.7) at c28b21aa6151a3f572d4b8ab066c96fe8fe72f94, synthetic fixtures only (no game data):

  • dotnet build tools/rpf9dump/rpf9dump.csproj -c Release — 0 warnings, 0 errors
  • dotnet run --project tests/Rpf9DumpDiagnostics/Rpf9DumpDiagnostics.csproj -c Release — all 6 suites passed (including new overflow and raw-block mismatch checks)
  • Filtered python -I tests/test_rpf9dump_exit_codes.py -v ... (all 8 non-blocker tests, including both new CLI tests) — 8 passed, 0 failed
  • Full python -I tests/test_rpf9dump_exit_codes.py — 8 passed, 2 pre-existing failures from main (test_failed_xma_write_exits_nonzero_and_rerun_completes & test_failed_texture_write_exits_nonzero_and_withholds_manifest due to b05999eb's Util.PartialName; fixed separately in #655)
  • python -I tests/test_ttpf_export_resume.py — 4 ran, OK
  • python -I tests/test_ci_registration.py — 15 ran, OK
  • python -I tests/test_text_write_line_endings.py — 3 ran, OK
  • python -I tests/test_check_no_game_data.py & python -I scripts/check_no_game_data.py — OK / exit 0
  • python -m compileall -q make_game.py tools tests — exit 0

GPUs tested: n/a

AI-assisted: yes

Checklist

  • Based on current main (21625bca) and merges cleanly (a conflicting pull request is labeled needs rebase).
  • One topic; follow-up work goes in a new pull request.
  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed. (n/a — rpf9dump only)

🔄 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/656 **Author:** [@kirigayakazima](https://github.com/kirigayakazima) **Created:** 11/24/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `fix/rpf9dump-segments-and-cli` --- ### 📝 Commits (1) - [`c28b21a`](https://github.com/ubiquitarianism/leonida/commit/c28b21aa6151a3f572d4b8ab066c96fe8fe72f94) rpf9dump: harden segment bounds and CLI option validation (RPF9DUMP-SEGMENTS-AND-CLI) ### 📊 Changes **4 files changed** (+49 additions, -5 deletions) <details> <summary>View changed files</summary> 📝 `tests/Rpf9DumpDiagnostics/Program.cs` (+9 -0) 📝 `tests/test_rpf9dump_exit_codes.py` (+28 -0) 📝 `tools/rpf9dump/Program.cs` (+8 -4) 📝 `tools/rpf9dump/Segments.cs` (+4 -1) </details> ### 📄 Description Claimed in the coordination issue as: RPF9DUMP-SEGMENTS-AND-CLI (https://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7129604877) ### What and why Follow-up hardening to merged #6344 (now on `main`) across `tools/rpf9dump/`: - `tools/rpf9dump/Segments.cs` (`RecoveredResource.Read`): - Prevent `Int64` overflow in `block.Offset + block.StoredSize > file.Length` by checking `block.Offset > file.Length || block.StoredSize > file.Length - block.Offset` (matching `RecoveryIndexCache`'s subtraction guard). Previously, e.g. `(Offset=32, StoredSize=long.MaxValue)` wrapped negative, passed the bounds check, and read a valid compressed stream starting at offset 32. - Reject raw blocks where `block.IsRaw && block.StoredSize != block.Size` with `InvalidDataException` instead of copying a partial or mismatched slice. - `tools/rpf9dump/Program.cs`: - Check unknown CLI options (`argv[i] is not ("--start" or "--length")`) **before** validating the value argument so bare `--bogus` or `--bogus notanumber` reports `Unknown option --bogus.` rather than claiming it `needs a non-negative byte count.`, and emit both diagnostics on `Console.Error`. - Parse `--jobs` with `NumberStyles.None, CultureInfo.InvariantCulture` (consistent with `--start` / `--length`) so `+2` / whitespace / locale digits are rejected cleanly with exit code 2. - `tests/Rpf9DumpDiagnostics/Program.cs` & `tests/test_rpf9dump_exit_codes.py`: - Add diagnostics cases for overflowing `StoredSize` and mismatched raw-block `StoredSize != Size` (both `>` and `<`). - Add exit-code tests for unknown options and invalid/signed/non-positive `--jobs` values leaving output directories uncreated. *(Keeps `tests/test_rpf9dump_exit_codes.py` lines 87–120 untouched so this merges cleanly alongside #655.)* ### Tested On Windows 11 x64 (`.NET 8.0.401`, `Python 3.14.7`) at `c28b21aa6151a3f572d4b8ab066c96fe8fe72f94`, synthetic fixtures only (no game data): - `dotnet build tools/rpf9dump/rpf9dump.csproj -c Release` — 0 warnings, 0 errors - `dotnet run --project tests/Rpf9DumpDiagnostics/Rpf9DumpDiagnostics.csproj -c Release` — all 6 suites passed (including new overflow and raw-block mismatch checks) - Filtered `python -I tests/test_rpf9dump_exit_codes.py -v ...` (all 8 non-blocker tests, including both new CLI tests) — 8 passed, 0 failed - Full `python -I tests/test_rpf9dump_exit_codes.py` — 8 passed, 2 pre-existing failures from `main` (`test_failed_xma_write_exits_nonzero_and_rerun_completes` & `test_failed_texture_write_exits_nonzero_and_withholds_manifest` due to `b05999eb`'s `Util.PartialName`; fixed separately in #655) - `python -I tests/test_ttpf_export_resume.py` — 4 ran, OK - `python -I tests/test_ci_registration.py` — 15 ran, OK - `python -I tests/test_text_write_line_endings.py` — 3 ran, OK - `python -I tests/test_check_no_game_data.py` & `python -I scripts/check_no_game_data.py` — OK / exit 0 - `python -m compileall -q make_game.py tools tests` — exit 0 GPUs tested: n/a AI-assisted: yes ### Checklist - [x] Based on current `main` (`21625bca`) and merges cleanly (a conflicting pull request is labeled `needs rebase`). - [x] One topic; follow-up work goes in a new pull request. - [x] No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here. - [ ] A new translator rule is in the contract table of `docs/design.md`, with how it was confirmed. (n/a — `rpf9dump` only) --- <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#695
No description provided.