mirror of
https://github.com/storytold/figcraft.git
synced 2026-11-02 06:46:50 -06:00
engine: long digit strings no longer overflow object.opacityKeys
opacity_from_digits multiplied and added on every character of its input string before the one-or-two-digit check, so "9999999999" overflowed u32 on the way (panic in debug builds, wrap in release). The scan now steps n with checked_mul/checked_add and stops (None) at the first character the number cannot take, so a long digit string is refused like any other bad input. Test: opacity_digits (engine keymap) covers the ten-digit string and the command's BadParams refusal.
This commit is contained in:
@@ -803,7 +803,8 @@ pub fn opacity_from_digits(digits: &str) -> Option<f32> {
|
||||
let mut n = 0u32;
|
||||
let mut count = 0;
|
||||
for c in digits.chars() {
|
||||
n = n * 10 + c.to_digit(10)?;
|
||||
// Input-derived: a number that outgrows `u32` stops the scan (None); it never wraps.
|
||||
n = n.checked_mul(10)?.checked_add(c.to_digit(10)?)?;
|
||||
count += 1;
|
||||
}
|
||||
match count {
|
||||
|
||||
Reference in New Issue
Block a user