diff --git a/crates/wasmparser/src/readers/core/reloc.rs b/crates/wasmparser/src/readers/core/reloc.rs index 42a2037854..4c48e4a37f 100644 --- a/crates/wasmparser/src/readers/core/reloc.rs +++ b/crates/wasmparser/src/readers/core/reloc.rs @@ -242,8 +242,12 @@ pub struct RelocationEntry { impl RelocationEntry { /// Byte range relative to the start of the section indicated by /// `RelocSectionReader::section` targeted by this relocation. - pub fn relocation_range(&self) -> Range { - (self.offset as usize)..(self.offset as usize + self.ty.extent()) + pub fn relocation_range(&self) -> Result> { + let start = self.offset as usize; + let end = start + .checked_add(self.ty.extent()) + .ok_or_else(|| crate::BinaryReaderError::new("relocation range end overflow", start))?; + Ok(start..end) } }