fix: use PathBuf instead of String for guest binary and crash dump paths#1652
fix: use PathBuf instead of String for guest binary and crash dump paths#1652midsterx wants to merge 1 commit into
Conversation
Signed-off-by: Midhush Karthic <mimosk25@gmail.com>
There was a problem hiding this comment.
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 usePathBufrather thanString. - Update crashdump plumbing to carry
PathBufthrough the API (generate_crashdump_to_dir,HYPERLIGHT_CORE_DUMP_DIR, file path formatting). - Update tests, examples, benches, and fuzz targets to pass
PathBufpaths; 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. |
| 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| { |
There was a problem hiding this comment.
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())); |
There was a problem hiding this comment.
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.
Currently, we do not allow non-UTF-8 paths for loading guest binaries and crash dumps. This PR replaces
String-backed filesystem paths withPathBuf, thus allowing non-UTF-8 paths.Resolves #1518