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

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

@⁠kirigayakazima on GitHub · 2026-11-24 11:06 UTC · original
kirigayakazima:fix/rpf9dump-segments-and-cli → main · +49 −5 · 4 files · 1 commits · open

Claimed in the coordination issue as: RPF9DUMP-SEGMENTS-AND-CLI (#14)

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)
**@⁠kirigayakazima** on GitHub · 2026-11-24 11:06 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/656) `kirigayakazima:fix/rpf9dump-segments-and-cli` → `main` · +49 −5 · 4 files · 1 commits · open Claimed in the coordination issue as: RPF9DUMP-SEGMENTS-AND-CLI (https://git.gtahub.st/github/ubiquitarianism--leonida/issues/14) ### 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)
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 09:14:16 +00:00
Author
Owner

@⁠PierreEbele on GitHub · 2026-11-25 02:47 UTC · original

Reviewed c28b21aa: read the full diff. The new bounds check (Offset > file.Length || StoredSize > file.Length - Offset) can no longer overflow; on main, Offset = 32, StoredSize = long.MaxValue wraps Offset + StoredSize negative and passes the check. The raw-size check also turns main's EndOfStreamException / silent short read for raw blocks with StoredSize != Size into a clean InvalidDataException. --jobs now parses with NumberStyles.None, so +2 is rejected, and unknown options are reported as unknown on stderr instead of as a byte-count error on stdout. Checked with a Python model of both sides, plus compileall and test_dotnet_rollforward.py (OK). I have no dotnet SDK here, so I couldn't run the .NET tests. No findings in the code.

One blocker: none of the new tests have run yet. In CI run 45381032677, check was cancelled at about 15 minutes, before the dedicated RPF9DUMP_DLL steps (.github/workflows/ci.yml:101-110). The generic test loop skipped all 10 test_rpf9dump_exit_codes.py tests because RPF9DUMP_DLL isn't set there. Please rebase or re-run so that check completes. Also, can you confirm the recovery scan only ever emits raw blocks with StoredSize == Size?

AI-assisted review.

Recommendation: Fix first

**@⁠PierreEbele** on GitHub · 2026-11-25 02:47 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/656#issuecomment-7151183738) Reviewed c28b21aa: read the full diff. The new bounds check (`Offset > file.Length || StoredSize > file.Length - Offset`) can no longer overflow; on main, `Offset = 32, StoredSize = long.MaxValue` wraps `Offset + StoredSize` negative and passes the check. The raw-size check also turns main's `EndOfStreamException` / silent short read for raw blocks with `StoredSize != Size` into a clean `InvalidDataException`. `--jobs` now parses with `NumberStyles.None`, so `+2` is rejected, and unknown options are reported as unknown on stderr instead of as a byte-count error on stdout. Checked with a Python model of both sides, plus `compileall` and `test_dotnet_rollforward.py` (OK). I have no dotnet SDK here, so I couldn't run the .NET tests. No findings in the code. One blocker: none of the new tests have run yet. In CI run 45381032677, `check` was cancelled at about 15 minutes, before the dedicated `RPF9DUMP_DLL` steps (`.github/workflows/ci.yml:101-110`). The generic test loop skipped all 10 `test_rpf9dump_exit_codes.py` tests because `RPF9DUMP_DLL` isn't set there. Please rebase or re-run so that `check` completes. Also, can you confirm the recovery scan only ever emits raw blocks with `StoredSize == Size`? AI-assisted review. **Recommendation:** Fix first
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/656/head:github-bot/gh-656'
git switch 'github-bot/gh-656'

Merge

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