Repository navigation
fix(io): reject NUL bytes in native file paths - #10303
Conversation
harisibrar1
left a comment
There was a problem hiding this comment.
Checked against main 7966e59 and core/relinker/io/src/{NativePath,FileReader,FileWriter}.cpp, main.cpp and wasm/Bindings.cpp on main:
- On main,
Io::NativePathpasses an embedded NUL through, so the nativeopensees only the prefix. All relinker string-to-path I/O goes through it (FileReader.cpp:13/30, FileWriter.cpp:91, main.cpp, NativeModules.cpp:36, CliArgs.cpp:215), so this one check covers them. - Command-line arguments can't carry a NUL. The reachable source I found is the wasm binding: JS strings go to
NativePathat Bindings.cpp:50/55/64, where:51checks for/and\but not NUL. Itsstd::exceptioncatch (:88) now reports the new error cleanly. std::invalid_argumentmatches io's existing use (BufferUtils.hpp:33), and the CLI's genericstd::exceptionhandler (main.cpp:479) prints it with exit code 2.- Optional: the message doesn't say which path was rejected. Including the part before the NUL would make a CLI failure easier to trace.
- The CMake registration follows the existing
autorun_exit_tests/cli_args_testspattern, and the branch still merges cleanly.
Reviewed with AI assistance (Claude Code); the checks above were run locally on my machine.
MarcZX10
left a comment
There was a problem hiding this comment.
The NUL guard is correctly placed before filesystem-path conversion, and the regression checks reader, both writer overloads, valid UTF-8/binary I/O, prefix-file preservation, and non-creation. The reported Windows full relinker suite, focused repeats, and WSL ASan/UBSan runs are strong; all hosted relinker checks are green. The NativePath implementation and test file are unchanged on current main; a merge-tree preview is clean, although core/relinker/CMakeLists.txt has changed since this branch's base.
Please update this branch to current main as required by CONTRIBUTING.md, then let the relinker and conventions checks run on that integration. The current head is based on b066e5c, 7,515 commits behind. I found no additional functional blocker in the reviewed diff.
|
Addressed in Revalidated this integration:
I also manually checked the latest bot's shared-CMake warnings for #5021, #6713 and #9408. Their registrations concern macOS fixtures, Windows process parameters and macOS import tracing, not this NUL guard or its test. Their existing base conflicts remain separate. The push starts fresh hosted relinker/conventions checks; those results are pending. No local macOS, title, GPU or full-product run is claimed. |
|
@MarcZX10 The branch is updated to current |
What
Io::NativePathaccepts strings containing embedded NUL bytes. Host file APIs can interpret such a path as the prefix before the NUL, allowing a read or write to target a different filename from the supplied string.Reject these inputs with
std::invalid_argumentbefore conversion or filesystem access. Empty strings and valid UTF-8 conversions keep their existing behaviour. This does not add guest filename restrictions or Windows-specific filename policy.The regression covers NULs at the start, middle and end, repeated NULs, valid UTF-8 round trips and binary file access. It checks rejection through the reader and both writer overloads, verifies an existing prefix-named file is unchanged, and verifies a missing prefix-named file is not created.
Tested
8dfc1ef5e5704d5bfc0b883f5011295d9c4a4335, including upstreammainat6f58a046b15c4fb3b4a19a7b5373a040c548c26bon 2026-10-25. Merged main without rewriting published history.NativePath.cppandNativePathTests.cppare byte-identical to the original reviewed head8cfa0cbf6f0a18d98d694a0891e5d4e679964cfd; the existing test registration merged cleanly with current CMake.NativePath.cpp, the newnative_pathregression fails withA path containing a NUL byte was accepted. Restoring the guard makes it pass.ANYPS5_RELINKER_ONLY=ON,BUILD_TESTING=ON: full relinker-only build succeeds; full CTest passes all 236 tests, with no CTest skips. The focusednative_path,cli_args,input_nonasciiandlong_pathstests each pass three consecutive runs.native_path,cli_args,input_nonasciiandlong_pathseach pass three consecutive CTest runs. Hosted checks on the updated head are pending, not claimed green yet.ANYPS5_ENABLE_ASAN=ONand-fsanitize=undefined:native_path,file_writer_binaryandfile_writer_texteach pass five consecutive CTest runs, with leak detection and ASan/UBSan halt-on-error enabled; no sanitizer diagnostics. The build/test temporary directories are on native Linux/tmp. An initial build under the Windows-mounted checkout passednative_pathfive times, but the two existing file-writer tests failed their permission-preservation checks on that mount; the native-filesystem runs pass without source changes.python tools/check_conventions.py --base origin/mainandgit diff --check origin/main...HEADpass. No macOS, full runtime, title or GPU run.native_path. Their existing base conflicts are not resolved by this PR. Original both-order merge checks with fix(relinker): probe masked store elements before the store under --to-rosetta #8142 and fix(relinker): keep registry offsets independent of host locale #10241 remain historical evidence, not a new integration claim.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)