From 6521389f7de5eafe64c1eac3bdb32470d02989e8 Mon Sep 17 00:00:00 2001 From: Vincent Thiberville Date: Mon, 8 Dec 2025 12:28:02 +0100 Subject: [PATCH] fix: do not panic on binrw backtrace error The ntfs crate could panic on some data because of a false "unreachable" instruction in error.rs: the binrw error is not guaranteed to only be an IO error, it can also be for example a backtrace error. Remove this unreachable which is too dangerous: any update of binrw could make this unreachable wrong, it is better to be conservative here. --- src/error.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/error.rs b/src/error.rs index 5dfe797..fab0757 100644 --- a/src/error.rs +++ b/src/error.rs @@ -27,6 +27,8 @@ pub enum NtfsError { expected: NtfsAttributeType, actual: NtfsAttributeType, }, + /// Error while deserializing data: {0:?} + BinrwError(binrw::error::Error), /// The given buffer should have at least {expected} bytes, but it only has {actual} bytes BufferTooSmall { expected: usize, actual: usize }, /// The NTFS Attribute at byte position {position:#x} has a length of {expected} bytes, but only {actual} bytes are left in the record @@ -232,8 +234,9 @@ impl From for NtfsError { if let binrw::error::Error::Io(io_error) = error { Self::Io(io_error) } else { - // We don't use any binrw attributes that result in other errors. - unreachable!("Got a binrw error of unexpected type: {:?}", error); + // Generic binrw error. This is generally a binrw::backtrace::Error that + // contains details about the parsing issue. + Self::BinrwError(error) } } }