From e5852a6100eef5e4172559dae5ea652d0c7f29d1 Mon Sep 17 00:00:00 2001 From: Johannes Altmanninger Date: Wed, 5 Mar 2025 07:58:38 +0100 Subject: [PATCH] Fix crash on negative stat f_type (Rust-port regression) Fixes #11219 --- src/path.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/path.rs b/src/path.rs index b9185680f..f4d75d3b8 100644 --- a/src/path.rs +++ b/src/path.rs @@ -707,7 +707,12 @@ fn path_remoteness(path: &wstr) -> DirRemoteness { // these are in varying headers. Simply hard code them. // Note that we treat FUSE filesystems as remote, which means we lock less on such filesystems. // NOTE: The cast is necessary for 32-bit systems because of the 4-byte CIFS_MAGIC_NUMBER - match usize::try_from(buf.f_type).unwrap() { + const _: () = assert!({ + use std::mem; + let f_type = unsafe { mem::zeroed::() }.f_type; + mem::size_of_val(&f_type) <= mem::size_of::() + }); + match buf.f_type as usize { 0x5346414F | // AFS_SUPER_MAGIC - Andrew File System 0x6B414653 | // AFS_FS_MAGIC - Kernel AFS and AuriStorFS 0x73757245 | // CODA_SUPER_MAGIC - Coda File System