From 7a2e70062cf0932ac27c2dbc9c41cbdc1ac21a38 Mon Sep 17 00:00:00 2001 From: edef Date: Sun, 23 Mar 2025 18:15:21 +0000 Subject: [PATCH] fix(snix/store/import): don't unsafely construct OsStr What we're doing is safe on POSIX, but not elsewhere, so we should use the Unix-only safe OsStr::from_bytes method rather than adding unsafety. Change-Id: Ib53edaec77a1a0aa2663287d973d398274fde79a Reviewed-on: https://cl.snix.dev/c/snix/+/30263 Tested-by: besadii Reviewed-by: Florian Klink --- snix/store/src/import.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/snix/store/src/import.rs b/snix/store/src/import.rs index be3041127..9cca30141 100644 --- a/snix/store/src/import.rs +++ b/snix/store/src/import.rs @@ -131,7 +131,7 @@ where #[cfg(test)] mod tests { - use std::{ffi::OsStr, path::PathBuf}; + use std::{ffi::OsStr, os::unix::ffi::OsStrExt, path::PathBuf}; use crate::import::path_to_name; use rstest::rstest; @@ -150,7 +150,7 @@ mod tests { #[case::path_ending_in_dotdot(b"a/b/..")] #[case::non_unicode_path(b"\xf8\xa1\xa1\xa1\xa1")] fn test_invalid_path_to_name(#[case] invalid_path: &[u8]) { - let path: PathBuf = unsafe { OsStr::from_encoded_bytes_unchecked(invalid_path) }.into(); + let path: PathBuf = OsStr::from_bytes(invalid_path).into(); path_to_name(&path).expect_err("must fail"); } }