Skip to content

fix: use PathBuf instead of String for guest binary and crash dump paths#1652

Open
midsterx wants to merge 1 commit into
hyperlight-dev:mainfrom
midsterx:fix/filepath
Open

fix: use PathBuf instead of String for guest binary and crash dump paths#1652
midsterx wants to merge 1 commit into
hyperlight-dev:mainfrom
midsterx:fix/filepath

Conversation

@midsterx

@midsterx midsterx commented Jul 17, 2026

Copy link
Copy Markdown

Currently, we do not allow non-UTF-8 paths for loading guest binaries and crash dumps. This PR replaces String-backed filesystem paths with PathBuf, thus allowing non-UTF-8 paths.

Resolves #1518

Signed-off-by: Midhush Karthic <mimosk25@gmail.com>

Copilot AI 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.

Pull request overview

This PR standardizes filesystem path handling in Hyperlight’s host/guest loading and crash dump code by replacing String-backed paths with PathBuf, improving correctness for non-UTF8 paths and reducing lossy conversions at API boundaries.

Changes:

  • Update GuestBinary::FilePath (and related callers) to use PathBuf rather than String.
  • Update crashdump plumbing to carry PathBuf through the API (generate_crashdump_to_dir, HYPERLIGHT_CORE_DUMP_DIR, file path formatting).
  • Update tests, examples, benches, and fuzz targets to pass PathBuf paths; add a Unix-only regression test for loading from a non-UTF8 filename.

Reviewed changes

Copilot reviewed 35 out of 35 changed files in this pull request and generated no comments.

Show a summary per file
File Description
src/hyperlight_testing/src/lib.rs Add *_as_pathbuf helpers; keep *_as_string wrappers for compatibility.
src/hyperlight_host/tests/wit_test.rs Switch test guest path acquisition to PathBuf.
src/hyperlight_host/tests/snapshot_goldens/fixtures.rs Use PathBuf for fixture guest binary paths.
src/hyperlight_host/tests/sandbox_host_tests.rs Update sandbox construction to pass PathBuf guest paths.
src/hyperlight_host/tests/common/mod.rs Return PathBuf guest paths for shared test helpers.
src/hyperlight_host/src/sandbox/uninitialized.rs Change GuestBinary::FilePath to PathBuf; update canonicalization and add non-UTF8 path test.
src/hyperlight_host/src/sandbox/uninitialized_evolve.rs Update evolve tests to use PathBuf guest paths.
src/hyperlight_host/src/sandbox/snapshot/mod.rs Pass PathBuf into ExeInfo::from_file during snapshot creation.
src/hyperlight_host/src/sandbox/snapshot/file_tests.rs Update snapshot tests and crashdump directory calls to PathBuf/&Path.
src/hyperlight_host/src/sandbox/outb.rs Update outb tests to use PathBuf guest paths.
src/hyperlight_host/src/sandbox/mod.rs Update sandbox module tests to use PathBuf guest paths.
src/hyperlight_host/src/sandbox/initialized_multi_use.rs Change generate_crashdump_to_dir to accept Into<PathBuf> and plumb into crashdump generator.
src/hyperlight_host/src/metrics/mod.rs Update metrics tests to use PathBuf guest paths.
src/hyperlight_host/src/mem/mgr.rs Update memory manager tests to use PathBuf guest paths.
src/hyperlight_host/src/mem/exe.rs Change ExeInfo::from_file to take &Path; update tests accordingly.
src/hyperlight_host/src/hypervisor/mod.rs Update hypervisor tests to use PathBuf guest paths.
src/hyperlight_host/src/hypervisor/hyperlight_vm/x86_64.rs Remove string filename extraction; pass Option<PathBuf> into crashdump context.
src/hyperlight_host/src/hypervisor/gdb/mod.rs Update GDB mem access tests to use PathBuf guest paths.
src/hyperlight_host/src/hypervisor/crashdump.rs Store binary path as PathBuf; use var_os and PathBuf end-to-end for output paths.
src/hyperlight_host/examples/tracing/main.rs Use PathBuf guest path helper in example.
src/hyperlight_host/examples/tracing-otlp/main.rs Use PathBuf guest path helper in example.
src/hyperlight_host/examples/tracing-chrome/main.rs Use PathBuf guest path helper in example.
src/hyperlight_host/examples/metrics/main.rs Use PathBuf guest path helper in example.
src/hyperlight_host/examples/map-file-cow-test/main.rs Pass PathBuf into GuestBinary::FilePath.
src/hyperlight_host/examples/logging/main.rs Use PathBuf guest path helper in example.
src/hyperlight_host/examples/hello-world/main.rs Pass PathBuf into GuestBinary::FilePath.
src/hyperlight_host/examples/guest-debugging/main.rs Pass PathBuf into GuestBinary::FilePath for debug example/tests.
src/hyperlight_host/examples/func_ctx/main.rs Use PathBuf guest path helper in example.
src/hyperlight_host/examples/crashdump/main.rs Update crashdump example functions to take &Path / use PathBuf throughout.
src/hyperlight_host/benches/benchmarks.rs Update benchmarks to pass PathBuf guest paths.
fuzz/fuzz_targets/host_print.rs Switch fuzz harness guest path acquisition to PathBuf.
fuzz/fuzz_targets/host_call.rs Switch fuzz harness guest path acquisition to PathBuf.
fuzz/fuzz_targets/guest_trace.rs Switch fuzz harness guest path acquisition to PathBuf.
fuzz/fuzz_targets/guest_call.rs Switch fuzz harness guest path acquisition to PathBuf.
CHANGELOG.md Document breaking API change: guest/crashdump path APIs now use PathBuf.

@jsturtevant jsturtevant added the kind/refactor For PRs that restructure or remove code without adding new functionality. label Jul 17, 2026
regs[26] = sregs.gs.selector as u64; // gs

// Get the filename from the binary path
let filename = self.rt_cfg.binary_path.clone().and_then(|path| {

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.

Why was this removed?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

It was removed because the filename duplicated information already contained in the binary PathBuf.

Previously, we stored both binary and filename. Now that we are using PathBuf, I removed filename from being passed.

The filename is derived later in crashdump.rs, where the ELF metadata actually requires text:

  let filename = ctx
      .binary
      .as_deref()
      .and_then(|path| path.file_name())
      .map_or("<unknown>".to_string(), |name| {
          name.to_string_lossy().into_owned()
      });

let temp_dir = tempfile::tempdir().unwrap();
let guest_path = temp_dir
.path()
.join(OsString::from_vec(b"guest-\xff".to_vec()));

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.

Does this file exist?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

The file does not exist yet. I intended to create it for testing purposes, which would automatically get deleted (by TempDir's Drop) at the end of the test function’s scope.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/refactor For PRs that restructure or remove code without adding new functionality.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

GuestBinary::FilePath takes path by String

3 participants