From cb19f3bd4d4ce8694460aa432180f85ad4f2efc1 Mon Sep 17 00:00:00 2001 From: Andrey Fedotov Date: Mon, 12 Sep 2022 06:33:06 +0300 Subject: [PATCH] pe: fix unbound access to bytes slice at im pe/debug.rs:172 --- src/pe/debug.rs | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/src/pe/debug.rs b/src/pe/debug.rs index b1da12c26..311bc632c 100644 --- a/src/pe/debug.rs +++ b/src/pe/debug.rs @@ -169,13 +169,18 @@ impl<'a> CodeviewPDB70DebugInfo<'a> { let mut signature: [u8; 16] = [0; 16]; signature.copy_from_slice(bytes.gread_with(&mut offset, 16)?); let age: u32 = bytes.gread_with(&mut offset, scroll::LE)?; - let filename = &bytes[offset..offset + filename_length]; - - Ok(Some(CodeviewPDB70DebugInfo { - codeview_signature, - signature, - age, - filename, - })) + if let Some(filename) = bytes.get(offset..offset + filename_length) { + Ok(Some(CodeviewPDB70DebugInfo { + codeview_signature, + signature, + age, + filename, + })) + } else { + Err(error::Error::Malformed(format!( + "ImageDebugDirectory seems corrupted: {:?}", + idd + ))) + } } }