Skip to content

Commit a373fa9

Browse files
steinwand6sylvestre
authored andcommitted
seq: add overflow checks when parsing decimal with exponent
1 parent 58dc3d0 commit a373fa9

1 file changed

Lines changed: 9 additions & 4 deletions

File tree

src/uu/seq/src/numberparse.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -219,10 +219,15 @@ fn parse_decimal_and_exponent(
219219
};
220220
// Special case: if the string is "-.1e2", we need to treat it
221221
// as if it were "-0.1e2".
222-
let total = if s.starts_with("-.") {
223-
i as i64 + exponent + 1
224-
} else {
225-
i as i64 + exponent
222+
let total = {
223+
let total = (i as i64)
224+
.checked_add(exponent)
225+
.ok_or(ParseNumberError::Float)?;
226+
if s.starts_with("-.") {
227+
total.checked_add(1).ok_or(ParseNumberError::Float)?
228+
} else {
229+
total
230+
}
226231
};
227232
if total < minimum as i64 {
228233
minimum

0 commit comments

Comments
 (0)