From 2c7f7b5cb0a7ab4dec9d039d57d049278b07c2ce Mon Sep 17 00:00:00 2001 From: Radmir Date: Mon, 29 Jul 2024 16:25:15 +0300 Subject: [PATCH] pe.cert_table: ignore malformed --- src/pe/mod.rs | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/src/pe/mod.rs b/src/pe/mod.rs index 3c8c3c3e..02d3cc44 100644 --- a/src/pe/mod.rs +++ b/src/pe/mod.rs @@ -3,12 +3,19 @@ // TODO: panics with unwrap on None for apisetschema.dll, fhuxgraphics.dll and some others -use core::cmp::max; - use alloc::borrow::Cow; use alloc::string::String; use alloc::vec::Vec; +use core::cmp::max; + +use log::debug; use log::warn; +use scroll::{ctx, Pwrite}; + +use crate::container; +use crate::error; +use crate::pe::utils::pad; +use crate::strtab; pub mod authenticode; pub mod certificate_table; @@ -29,15 +36,6 @@ pub mod symbol; pub mod tls; pub mod utils; -use crate::container; -use crate::error; -use crate::pe::utils::pad; -use crate::strtab; - -use scroll::{ctx, Pwrite}; - -use log::debug; - #[derive(Debug)] /// An analyzed PE32/PE32+ binary pub struct PE<'a> { @@ -142,7 +140,7 @@ impl<'a> PE<'a> { return Err(error::Error::Malformed(format!( "Unsupported header magic ({:#x})", magic - ))) + ))); } }; @@ -268,7 +266,11 @@ impl<'a> PE<'a> { bytes, certificate_table.virtual_address, certificate_table.size, - )?; + ) + .unwrap_or_else(|err| { + warn!("Cannot parse CertificateTable: {:?}", err); + Default::default() + }); certificate_table.size as usize } else {