Repository navigation
rpf9dump: harden Util.Safe for cross-platform and Windows filenames - #2876
Conversation
KelboLive
left a comment
There was a problem hiding this comment.
Sanitising every component before Path.Combine, the post-truncation trim, and the reserved-name stem split (first ., spaces trimmed so CON .txt matches) all look right, and the nasty cases stay inert: ../../etc/passwd → _.._etc_passwd, ..\..\windows\system32 → _.._windows_system32, CON → _CON, foo./foo → foo, 300 chars → 120 with no trailing dot. COM0/COM10 are correctly allowed. Build clean, diagnostics all pass, test_rpf9dump_exit_codes.py 10/10.
Two real gaps:
- The headline cross-platform rule is untested. The explicit
<>:"/\|?*list pluschar.IsControlis now a strict superset of Windows'Path.GetInvalidFileNameChars(), so that call is dead code — and deleting the<>:"/\|?*clause leaves all tests green, because the diagnostics job runs only onwindows-latest(.github/workflows/ci.yml:87,:140). Either drop the platform call soSafeis deterministic and the test becomes real, or run the diagnostics on a Unix runner too. - The
_escape creates collisions.CON→_CONand a genuine_CON(likewiseNUL.txt/_NUL.txt) map to the same file, and every exporter treatsFile.Existsas success (Program.cs:313,:327,:360,:157), so the loser is silently skipped and the manifest lists the sameFile/Dirtwice. Prefer a non-colliding escape (CON_,%5F) or uniquify with the entry offset. The same class already exists forfoo./foo,a:b/a*b/a_b,.../""/x, and truncation that drops the extension (119a + ".x"and119a + ".y"both →119a); index-prefixed call sites are immune, stem-derived directories are not.
Also worth fixing while here:
- Truncation can split a surrogate pair: 119 ×
a+ 😀 ends in a loneU+D83D. Cut on a code-point boundary. - The archive base name is never sanitised (
Program.cs:70-71,outDir = Path.Combine(outRoot, Path.GetFileNameWithoutExtension(src))) — the one written component that skipsSafe. - Minor: per-component 120 is bounded but the total path is not (
\\?\unused; nestedmodels/<120>/<120>_tex/…can exceed MAX_PATH), andCONIN$/CONOUT$/COM¹are still device names.
|
Merging (added to the merge queue). Head f2357fa merges cleanly with main c4ca576. Claim: RPF9DUMP-UTIL-SAFE-WINDOWS-NAMES (#2570 (comment)). Red/green: KelboLive review on this head (sanitising and reserved names checked case by case); tool-only change. I ran: #2858, #2882, #2788, #2876 and #2884 merged together onto main c4ca576: cargo tests leonida-shader 420 passed / 0 failed, leonida-loader 85/0, leonida-gpu 644/0. In-game run: RTX 4070 Laptop 8 GB, NVIDIA 621.40, -SeriesS -NoDlss -NoFrameGen, a cold start to the world (135 s) then a 330 s warm walking run: median 35.4 ms (28.2 fps), private memory max 24.4 GB, 0 device lost. CI: green on head and main; the queue runs the full CI on the group before merging. AI-assisted: Claude Code (oreofr-agent), merge approved in writing by OreoFR. |
Claimed in the coordination issue as: RPF9DUMP-UTIL-SAFE-WINDOWS-NAMES (#2570 (comment))
What and why
Hardens
Util.Safe(string s)intools/rpf9dump/Util.csagainst three filename edge cases when exporting archives/textures:Path.GetInvalidFileNameChars()and control characters were replaced with'_'. On Linux/macOS that set only includes'\0'and'/', leaving<>:"/\|?*unsanitized across hosts.Util.Safenow sanitizes<>:"/\|?*uniformly everywhere..Trim(' ', '.')ran only before[..Math.Min(120, v.Length)], so names like"a" * 119 + ".foo"or"a" + "." * 130 + "b"ended with a trailing.or' 'after truncation (rejected/stripped on Windows).Util.Safenow trims trailing spaces/dots after truncation as well (returning"x"if empty).'.'(trimmed of trailing spaces) isCON,PRN,AUX,NUL,COM1..COM9, orLPT1..LPT9(case-insensitive) are prefixed with'_'and bounded to 120 chars without trailing dots/spaces.Tested
Verified locally (Windows 11, .NET SDK 8.0.401, Python 3.14, no game data):
dotnet run --project tests/Rpf9DumpDiagnostics/Rpf9DumpDiagnostics.csproj -c Releasefailed ontrailing dot after 120-char truncation.dotnet build tools/rpf9dump/rpf9dump.csproj -c Release: 0 warnings, 0 errorsdotnet run --project tests/Rpf9DumpDiagnostics/Rpf9DumpDiagnostics.csproj -c Release: all 7 test groups passed (Util.Safe filename tests passed.)python -I tests/test_rpf9dump_exit_codes.py(with builtRPF9DUMP_DLL): 10 passedpython -I scripts/check_no_game_data.py&git diff --check: cleanGPUs tested: n/a
AI-assisted: yes
Checklist
mainand merges cleanly (a conflicting pull request is labeledneeds rebase).docs/design.md, with how it was confirmed. (n/a)