Skip to content

Commit d41866b

Browse files
pe: fix PE relocations parser
resolve #1362
1 parent a01d9d8 commit d41866b

2 files changed

Lines changed: 23 additions & 1 deletion

File tree

src/PE/Parser.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,13 @@ ok_error_t Parser::parse_relocations() {
395395
break;
396396
}
397397

398+
if (raw_struct.BlockSize > max_offset - current_offset) {
399+
LIEF_ERR("Corrupted relocation: BlockSize ({}) exceeds remaining relocation "
400+
"directory size ({})",
401+
raw_struct.BlockSize, max_offset - current_offset);
402+
break;
403+
}
404+
398405
if (raw_struct.BlockSize > binary_->optional_header().sizeof_image()) {
399406
LIEF_ERR("Corrupted relocation: BlockSize exceeds binary virtual size: "
400407
"{0} ({0:#10x})",

tests/pe/test_parser.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
import lief
99
import pytest
10-
from utils import get_sample, is_64bits_platform, parse_pe
10+
from utils import address_space_limiter, get_sample, is_64bits_platform, parse_pe
1111

1212

1313
def test_dos_header():
@@ -1207,3 +1207,18 @@ def test_coff_string_table_offset_overflow():
12071207
pe = lief.PE.parse(sample)
12081208
assert pe is not None
12091209
assert len(pe.coff_string_table) == 0
1210+
1211+
1212+
@pytest.mark.private
1213+
def test_issue_1362():
1214+
sample = Path(get_sample("private/PE/issue_1362.pe")).absolute()
1215+
subprocess.check_call(
1216+
[
1217+
sys.executable,
1218+
"-c",
1219+
"import lief; import sys; lief.parse(sys.argv[1])",
1220+
str(sample),
1221+
],
1222+
timeout=30.0,
1223+
preexec_fn=address_space_limiter(),
1224+
)

0 commit comments

Comments
 (0)