Skip to content

fix(io): reject NUL bytes in native file paths - #10303

Merged
oneandonlydean merged 2 commits into
boykopovar:mainfrom
Bram910:fix/native-path-null-bytes
Oct 26, 2026
Merged

oneandonlydean merged 2 commits into
boykopovar:mainfrom
Bram910:fix/native-path-null-bytes

Conversation

@Bram910

@Bram910 Bram910 commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

What

Io::NativePath accepts 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_argument before 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

  • Updated integration head 8dfc1ef5e5704d5bfc0b883f5011295d9c4a4335, including upstream main at 6f58a046b15c4fb3b4a19a7b5373a040c548c26b on 2026-10-25. Merged main without rewriting published history. NativePath.cpp and NativePathTests.cpp are byte-identical to the original reviewed head 8cfa0cbf6f0a18d98d694a0891e5d4e679964cfd; the existing test registration merged cleanly with current CMake.
  • Negative control: using main's unmodified NativePath.cpp, the new native_path regression fails with A path containing a NUL byte was accepted. Restoring the guard makes it pass.
  • Original head: Windows x64, MinGW-w64 GCC 14.1.0 UCRT, Release, ANYPS5_RELINKER_ONLY=ON, BUILD_TESTING=ON: full relinker-only build succeeds; full CTest passes all 236 tests, with no CTest skips. The focused native_path, cli_args, input_nonascii and long_paths tests each pass three consecutive runs.
  • Updated integration: the same Windows Release relinker-only configuration builds successfully; full CTest 261/261 passed, no CTest skips, in 160.27 seconds. native_path, cli_args, input_nonascii and long_paths each pass three consecutive CTest runs. Hosted checks on the updated head are pending, not claimed green yet.
  • Updated integration: Ubuntu 22.04 under WSL, GCC 11.4.0, Debug, ANYPS5_ENABLE_ASAN=ON and -fsanitize=undefined: native_path, file_writer_binary and file_writer_text each 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 passed native_path five 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/main and git diff --check origin/main...HEAD pass. No macOS, full runtime, title or GPU run.
  • Original overlap scan reported no confirmed conflicts, duplicate exports or same new files, with shared-file comparison warnings for feat(aot): consolidate native ARM64 compiler, runtime and consumers #5021, test: organize library tests and label CTest suites #6044 and feat(relinker): trace function imports on macOS #9408. The latest bot warning names feat(aot): consolidate native ARM64 compiler, runtime and consumers #5021, fix(libc): use the default heap for an executable without process parameters #6713 and feat(relinker): trace function imports on macOS #9408 instead; manually rechecked their current CMake patches on 2026-10-25: they register macOS fixtures, Windows process-parameter tests and macOS import tracing respectively, not NUL-path validation or 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

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes, Codex

@github-actions

github-actions Bot commented Oct 23, 2026 •

Copy link
Copy Markdown

Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.

Pull request Shared files not compared
PR 5021 core/relinker/CMakeLists.txt
PR 6713 core/relinker/CMakeLists.txt

@harisibrar1 harisibrar1 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Checked against main 7966e59 and core/relinker/io/src/{NativePath,FileReader,FileWriter}.cpp, main.cpp and wasm/Bindings.cpp on main:

  • On main, Io::NativePath passes an embedded NUL through, so the native open sees 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 NativePath at Bindings.cpp:50/55/64, where :51 checks for / and \ but not NUL. Its std::exception catch (:88) now reports the new error cleanly.
  • std::invalid_argument matches io's existing use (BufferUtils.hpp:33), and the CLI's generic std::exception handler (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_tests pattern, and the branch still merges cleanly.

Reviewed with AI assistance (Claude Code); the checks above were run locally on my machine.

@MarcZX10 MarcZX10 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@Bram910

Bram910 commented Oct 25, 2026

Copy link
Copy Markdown
Contributor Author

Addressed in 8dfc1ef5e5704d5bfc0b883f5011295d9c4a4335: merged upstream main 6f58a046b15c4fb3b4a19a7b5373a040c548c26b into this branch without rewriting published history. The NUL guard and its regression source are byte-identical to the reviewed head; the CMake registration merged cleanly.

Revalidated this integration:

  • Windows MinGW Release relinker-only build succeeds; full CTest 261/261 passed. native_path, cli_args, input_nonascii and long_paths each pass three consecutive runs.
  • Linux GCC Debug ASan+UBSan: native_path, file_writer_binary and file_writer_text each pass five consecutive CTest runs using native Linux temporary storage, with leak detection and halt-on-error enabled and no sanitizer diagnostics. The initial Windows-mounted build passed the native-path test but exposed the existing file-writer permission checks on that filesystem; native-filesystem runs pass without source changes.
  • Conventions and whitespace checks pass. The updated description distinguishes the original-head results from these integration results.

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.

@Bram910

Bram910 commented Oct 25, 2026

Copy link
Copy Markdown
Contributor Author

@MarcZX10 The branch is updated to current main as you asked: 8dfc1ef5e5 merges upstream main 6f58a046b1 without rewriting history, and the hosted relinker and conventions checks have run on that merge (details in my comment above). The NUL guard and its test are unchanged from the head you reviewed. Could you take another look when you have time?

@oneandonlydean
oneandonlydean merged commit db1a91f into boykopovar:main Oct 26, 2026
13 of 14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants