Skip to content

Commit 3f5b4c7

Browse files
committed
Limit resource names to 1000 character at most.
Fixes high memory usage with corrupt files like bd15a7227770d89546e0a16e4c8da45937d970baa810827a7ceb17abd3138fec.
1 parent 0e5b6bb commit 3f5b4c7

File tree

1 file changed

+4
-2
lines changed
  • libyara/modules/pe

1 file changed

+4
-2
lines changed

libyara/modules/pe/pe.c

+4-2
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,6 @@ static void pe_parse_debug_directory(PE* pe)
380380
// Return a pointer to the resource directory string or NULL.
381381
// The callback function will parse this and call yr_set_sized_string().
382382
// The pointer is guaranteed to have enough space to contain the entire string.
383-
384383
static const PIMAGE_RESOURCE_DIR_STRING_U parse_resource_name(
385384
PE* pe,
386385
const uint8_t* rsrc_data,
@@ -397,10 +396,13 @@ static const PIMAGE_RESOURCE_DIR_STRING_U parse_resource_name(
397396

398397
// A resource directory string is 2 bytes for the length and then a variable
399398
// length Unicode string. Make sure we have at least 2 bytes.
400-
401399
if (!fits_in_pe(pe, pNameString, 2))
402400
return NULL;
403401

402+
// Sanity check for strings that are excesively large.
403+
if (pNameString->Length > 1000)
404+
return NULL;
405+
404406
// Move past the length and make sure we have enough bytes for the string.
405407
if (!fits_in_pe(
406408
pe,

0 commit comments

Comments
 (0)