rpf9dump: harden segment bounds and CLI option validation (RPF9DUMP-SEGMENTS-AND-CLI) #656
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/656"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from ubiquitarianism/leonida. Originally posted by kirigayakazima on 2026-11-24T11:06:03Z.
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) acrosstools/rpf9dump/:tools/rpf9dump/Segments.cs(RecoveredResource.Read):Int64overflow inblock.Offset + block.StoredSize > file.Lengthby checkingblock.Offset > file.Length || block.StoredSize > file.Length - block.Offset(matchingRecoveryIndexCache'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.block.IsRaw && block.StoredSize != block.SizewithInvalidDataExceptioninstead of copying a partial or mismatched slice.tools/rpf9dump/Program.cs:argv[i] is not ("--start" or "--length")) before validating the value argument so bare--bogusor--bogus notanumberreportsUnknown option --bogus.rather than claiming itneeds a non-negative byte count., and emit both diagnostics onConsole.Error.--jobswithNumberStyles.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:StoredSizeand mismatched raw-blockStoredSize != Size(both>and<).--jobsvalues leaving output directories uncreated.(Keeps
tests/test_rpf9dump_exit_codes.pylines 87–120 untouched so this merges cleanly alongside #655.)Tested
On Windows 11 x64 (
.NET 8.0.401,Python 3.14.7) atc28b21aa6151a3f572d4b8ab066c96fe8fe72f94, synthetic fixtures only (no game data):dotnet build tools/rpf9dump/rpf9dump.csproj -c Release— 0 warnings, 0 errorsdotnet run --project tests/Rpf9DumpDiagnostics/Rpf9DumpDiagnostics.csproj -c Release— all 6 suites passed (including new overflow and raw-block mismatch checks)python -I tests/test_rpf9dump_exit_codes.py -v ...(all 8 non-blocker tests, including both new CLI tests) — 8 passed, 0 failedpython -I tests/test_rpf9dump_exit_codes.py— 8 passed, 2 pre-existing failures frommain(test_failed_xma_write_exits_nonzero_and_rerun_completes&test_failed_texture_write_exits_nonzero_and_withholds_manifestdue tob05999eb'sUtil.PartialName; fixed separately in #655)python -I tests/test_ttpf_export_resume.py— 4 ran, OKpython -I tests/test_ci_registration.py— 15 ran, OKpython -I tests/test_text_write_line_endings.py— 3 ran, OKpython -I tests/test_check_no_game_data.py&python -I scripts/check_no_game_data.py— OK / exit 0python -m compileall -q make_game.py tools tests— exit 0GPUs tested: n/a
AI-assisted: yes
Checklist
main(21625bca) and merges cleanly (a conflicting pull request is labeledneeds rebase).docs/design.md, with how it was confirmed. (n/a —rpf9dumponly)Imported from ubiquitarianism/leonida. Originally posted by PierreEbele on 2026-11-25T02:47:07Z.
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.MaxValuewrapsOffset + StoredSizenegative and passes the check. The raw-size check also turns main'sEndOfStreamException/ silent short read for raw blocks withStoredSize != Sizeinto a cleanInvalidDataException.--jobsnow parses withNumberStyles.None, so+2is 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, pluscompileallandtest_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,
checkwas cancelled at about 15 minutes, before the dedicatedRPF9DUMP_DLLsteps (.github/workflows/ci.yml:101-110). The generic test loop skipped all 10test_rpf9dump_exit_codes.pytests becauseRPF9DUMP_DLLisn't set there. Please rebase or re-run so thatcheckcompletes. Also, can you confirm the recovery scan only ever emits raw blocks withStoredSize == Size?AI-assisted review.
Recommendation: Fix first
Imported from ubiquitarianism/leonida. Originally posted by zmasi on 2026-11-28T22:00:48Z.
Native Windows 11 +
.NET SDK 8.0.428Verification (c28b21aa61)Verified
c28b21aa6151a3f572d4b8ab066c96fe8fe72f94merged cleanly ontoorigin/main(c7753ed98a56677f10e34078b37eab0540e190ec,git merge-tree --write-treerc=0) on native Windows 11 (26200) +.NET SDK 8.0.428+ Python3.12.10:origin/mainc7753ed98a):dotnet run --project tests/Rpf9DumpDiagnostics: failed with unhandled CLR exception (rc=0xE0434352—Offset = 32, StoredSize = long.MaxValueoverflowedblock.Offset + block.StoredSizenegative past the bounds check, and raw blocks withStoredSize != Sizewere not rejected).python -I tests/test_rpf9dump_exit_codes.py(with Releaserpf9dump.dll):FAILED (failures=5)out of10tests (--bogusreported a byte-count message onstdoutinstead ofUnknown option --bogus.onstderr, and--jobs +2was accepted).origin/main + c28b21aa61):dotnet run --project tests/Rpf9DumpDiagnostics:6/6diagnostic groups passed (rc=0) (Model decode,Atomic write,Scan count,Mesh key,Recovered segment,Cached index).python -I tests/test_rpf9dump_exit_codes.py(with Releaserpf9dump.dll):10/10 OK(rc=0) with zero output directories created on invalid CLI options.AI-assisted.
Imported from ubiquitarianism/leonida. Originally posted by OreoFR on 2026-11-29T01:40:23Z.
Verified by OreoFR on macOS 27.2.1 (26B131), Apple M5, APFS (case-insensitive), Python 3.12.16, .NET SDK 11.0.100, main
53b77df14: red = main / green = main + this PRgit submodule update --init,dotnet build tools/rpf9dump/rpf9dump.csproj -c Release,RPF9DUMP_DLLset to that build) with the test file as merged; green = main +git merge --no-ffof this PR (clean), rpf9dump built from the merged tree.python -I tests/test_rpf9dump_exit_codes.py:test_jobs_rejects_signed_or_nonpositive_values(case--jobs +2): main accepts+2then crashes with an unhandled "Truncated RDS5 header" exception, exit -6 (expected 2).test_unknown_option_reports_unknown_option_before_creating_output(cases--bogusand--bogus notanumber): "Unknown option --bogus" missing from stderr; main prints option errors to stdout, and the two-argument case hits the byte-count check first.tests/Rpf9DumpDiagnostics(dotnet run --project tests/Rpf9DumpDiagnostics/... -c Release, as CI runs it):Program.cs:107, exit 134).No test skipped on macOS.
Verdict: READY.
AI-assisted: Claude Code (Claude Opus 5.5).
Imported from ubiquitarianism/leonida. Originally posted by kirigayakazima on 2026-12-01T11:18:24Z.
Merged
upstream/main(3ee508b46) into this branch atb13b6b3d3(no rebase, no force-push) so fresh CI runs on currentmain.Thanks @PierreEbele, @zmasi, and @OreoFR for the detailed review and verification! Regarding @PierreEbele's question:
StoredSize == Size:Rpf9TextureRecovery(third_party/rpf9-explorer/Core/Rpf9TextureRecovery.cs) never emitsIsRawsegments, and the only placeIsRaw = trueis set isRpf9ModelRecovery.TryRawTail(third_party/rpf9-explorer/Core/Rpf9ModelRecovery.cs:237,261), wherePackedequalstail.Length(Data.Length) andRecoverAtOffsets(:99) constructsnew ArchiveSegment(block.Offset, block.Packed, block.Data.Length) { IsRaw = block.IsRaw }. BothZlibSegmentsStream.cs:18andRecoveryIndexCache.cs:114also enforcesegment.StoredSize == segment.Sizewhensegment.IsRawis true.Verification at
b13b6b3d3(Windows 11,.NET SDK 8.0.401, Python 3.12, no game data)dotnet build tools/rpf9dump/rpf9dump.csproj -c Release: 0 warnings, 0 errorsdotnet run --project tests/Rpf9DumpDiagnostics/Rpf9DumpDiagnostics.csproj -c Release: 6/6 diagnostic groups passed (Model decode,Atomic write,Scan count,Mesh key,Recovered segment,Cached index)python -I tests/test_rpf9dump_exit_codes.py(withRPF9DUMP_DLLpointing to the Release build): 10/10 OK (0 skipped)python -I tests/test_text_write_line_endings.py: 3 tests OKpython -I scripts/check_no_game_data.py&git diff --check upstream/main...HEAD: clean (exit 0)AI-assisted.
Imported from ubiquitarianism/leonida. Originally posted by aslan2142 on 2026-12-01T11:33:13Z.
Review: APPROVED
Reviewed the diff against
main:tools/rpf9dump/Segments.cs:110-114cleanly fixes integer overflow in the segment-bounds check and rejects mismatched rawStoredSize != Size,tools/rpf9dump/Program.cs:75-97validates unknown options and--jobswithNumberStyles.Nonebefore creating output, and tests intests/Rpf9DumpDiagnostics/Program.csandtests/test_rpf9dump_exit_codes.pycover all edge cases. Clean-room verified. Approving; awaiting completion of in-progress CI checks before merge.(AI-assisted review.)