Skip to content

Commit 6cea41b

Browse files
committed
fix: modifier depth between 1<<30 and u32::MAX
1 parent 48456d6 commit 6cea41b

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

crates/artifacts/solc/src/sourcemap.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -246,8 +246,12 @@ impl SourceElement {
246246
}
247247

248248
#[inline]
249-
fn set_modifier_depth(&mut self, modifier_depth: u32) {
250-
self.set_jump_and_modifier_depth(self.jump(), modifier_depth);
249+
fn set_modifier_depth(&mut self, modifier_depth: usize) -> Result<(), SyntaxError> {
250+
if modifier_depth > (1 << 30) - 1 {
251+
return Err(SyntaxError::new(None, "modifier depth overflow"));
252+
}
253+
self.set_jump_and_modifier_depth(self.jump(), modifier_depth as u32);
254+
Ok(())
251255
}
252256

253257
#[inline]
@@ -369,7 +373,7 @@ impl SourceElementBuilder {
369373
get_field!(|jump| element.set_jump(jump));
370374
// Modifier depth is optional.
371375
if let Some(modifier_depth) = self.modifier_depth {
372-
element.set_modifier_depth(modifier_depth.try_into()?);
376+
element.set_modifier_depth(modifier_depth)?;
373377
}
374378
Ok(element)
375379
}

0 commit comments

Comments
 (0)