Skip to content

Commit 4cd5e1f

Browse files
autoBojunChai
authored andcommitted
fix(size): avoid u64 overflow panic when parsing huge size args
Parsing size arguments like '+20000000T' used to panic due to unchecked multiplication of quantity by the unit multiplier. Use checked_mul so invalid (too-large) inputs are rejected as an error from the CLI instead of aborting the process.
1 parent 90e73d7 commit 4cd5e1f

1 file changed

Lines changed: 3 additions & 1 deletion

File tree

src/filter/size.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ impl SizeFilter {
5656
_ => return None,
5757
};
5858

59-
let size = quantity * multiplier;
59+
let size = quantity.checked_mul(multiplier)?;
6060
match limit_kind {
6161
"+" => Some(SizeFilter::Min(size)),
6262
"-" => Some(SizeFilter::Max(size)),
@@ -191,6 +191,8 @@ mod tests {
191191
ensure_invalid_unit_returns_none_3: "+1Mv",
192192
ensure_bib_format_returns_none: "+1bib",
193193
ensure_bb_format_returns_none: "+1bb",
194+
ensure_overflow_returns_none_tib: "+17000000Ti",
195+
ensure_overflow_returns_none_tb: "+20000000T",
194196
}
195197

196198
#[test]

0 commit comments

Comments
 (0)