Skip to content

Commit 44fd094

Browse files
committed
Fix regression introduced in 6209630
One section entry was being ignored while parsing file b200f89fe313b6311e444e37725cae95127797ddb430e711c788c264acf92eb0 because we were forcing every resource entry to be shorter than the PE itself. Although this sanity check makes sense, with truncated files this can lead to resource entries that are ignored. Here we make the sanity check more permissive, allowing entries that are larger than the PE file, but rejecting entries with ridiculously large sizes.
1 parent 5194025 commit 44fd094

File tree

1 file changed

+5
-1
lines changed
  • libyara/modules/pe

1 file changed

+5
-1
lines changed

libyara/modules/pe/pe.c

+5-1
Original file line numberDiff line numberDiff line change
@@ -509,7 +509,11 @@ static int _pe_iterate_resources(
509509
if (struct_fits_in_pe(pe, data_entry, IMAGE_RESOURCE_DATA_ENTRY))
510510
{
511511
if (yr_le32toh(data_entry->Size) > 0 &&
512-
yr_le32toh(data_entry->Size) < pe->data_size)
512+
// We could use the PE's size as an upper bound for the entry size,
513+
// but there are some truncated files where the PE size is lower.
514+
// Use a reasonably large value as the upper bound and avoid some
515+
// completely corrupt entries with random values.
516+
yr_le32toh(data_entry->Size) <= 0x3FFFFFFF)
513517
{
514518
if (callback(
515519
data_entry,

0 commit comments

Comments
 (0)