Skip to content

Commit

Permalink
Fix overflow in Sat::from_name (#2500)
Browse files Browse the repository at this point in the history
  • Loading branch information
casey authored Oct 9, 2023
1 parent 4152d48 commit c811d48
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/sat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,13 @@ impl Sat {
match c {
'a'..='z' => {
x = x * 26 + c as u64 - 'a' as u64 + 1;
if x > Self::SUPPLY {
bail!("sat name out of range");
}
}
_ => bail!("invalid character in sat name: {c}"),
}
}
if x > Self::SUPPLY {
bail!("sat name out of range");
}
Ok(Sat(Self::SUPPLY - x))
}

Expand Down Expand Up @@ -543,6 +543,7 @@ mod tests {
assert!(parse("(").is_err());
assert!(parse("").is_err());
assert!(parse("nvtdijuwxlq").is_err());
assert!(parse("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa").is_err());
}

#[test]
Expand Down

0 comments on commit c811d48

Please sign in to comment.