Skip to content

Commit

Permalink
fix: limit the number of resources extracted from a PE file
Browse files Browse the repository at this point in the history
  • Loading branch information
plusvic committed Nov 15, 2023
1 parent d0b2756 commit 562c0f8
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions yara-x/src/modules/pe/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,7 @@ impl<'a> PE<'a> {

const MAX_PE_SECTIONS: usize = 96;
const MAX_PE_IMPORTS: usize = 16384;
const MAX_PE_RESOURCES: usize = 65535;
const MAX_DIR_ENTRIES: usize = 16;

fn parse_dos_header(input: &[u8]) -> IResult<&[u8], DOSHeader> {
Expand Down Expand Up @@ -1233,6 +1234,10 @@ impl<'a> PE<'a> {
} else if let Ok((_, rsrc_entry)) =
Self::parse_rsrc_entry(entry_data)
{
if resources.len() == Self::MAX_PE_RESOURCES {
return Some(resources);
}

resources.push(Resource {
type_id: ids.0,
rsrc_id: ids.1,
Expand Down

0 comments on commit 562c0f8

Please # to comment.