From 15f13f74b67a8d46d8429d7f53128a167c84eebd Mon Sep 17 00:00:00 2001 From: Johannes Stoelp Date: Thu, 28 Apr 2022 19:39:28 +0200 Subject: check mul/add when indexing into phdr --- src/lib.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index d3f5b4e..a5d3a7c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -242,7 +242,8 @@ impl Elf<'_> { let phoff = usize::try_from(phoff).expect("phoff too large!"); for ph in 0..phnum { - let pos = phoff + usize::from(ph * phentsize); + let off = ph.checked_mul(phentsize).map(usize::from).expect("phdr offset overflowed"); + let pos = phoff.checked_add(off).expect("phdr position overflowed"); r.set_pos(pos); // We only care about load segments. -- cgit v1.2.3