From 6cea41bfca59b9f54f72237d98b8b99d80089e74 Mon Sep 17 00:00:00 2001 From: DaniPopes <57450786+DaniPopes@users.noreply.github.com> Date: Tue, 17 Sep 2024 16:19:22 +0200 Subject: [PATCH] fix: modifier depth between 1<<30 and u32::MAX --- crates/artifacts/solc/src/sourcemap.rs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/crates/artifacts/solc/src/sourcemap.rs b/crates/artifacts/solc/src/sourcemap.rs index 6e8329ad..8c0f33a2 100644 --- a/crates/artifacts/solc/src/sourcemap.rs +++ b/crates/artifacts/solc/src/sourcemap.rs @@ -246,8 +246,12 @@ impl SourceElement { } #[inline] - fn set_modifier_depth(&mut self, modifier_depth: u32) { - self.set_jump_and_modifier_depth(self.jump(), modifier_depth); + fn set_modifier_depth(&mut self, modifier_depth: usize) -> Result<(), SyntaxError> { + if modifier_depth > (1 << 30) - 1 { + return Err(SyntaxError::new(None, "modifier depth overflow")); + } + self.set_jump_and_modifier_depth(self.jump(), modifier_depth as u32); + Ok(()) } #[inline] @@ -369,7 +373,7 @@ impl SourceElementBuilder { get_field!(|jump| element.set_jump(jump)); // Modifier depth is optional. if let Some(modifier_depth) = self.modifier_depth { - element.set_modifier_depth(modifier_depth.try_into()?); + element.set_modifier_depth(modifier_depth)?; } Ok(element) }