From 8b6d754fa7803bd72e4b0c20de48d7fed9805923 Mon Sep 17 00:00:00 2001 From: parneetsingh022 Date: Mon, 26 Oct 2026 16:08:28 -0700 Subject: [PATCH 1/3] fix: prevent integer overflow when parsing size filters --- src/filter/size.rs | 41 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) diff --git a/src/filter/size.rs b/src/filter/size.rs index 32c0f4c..740ca0c 100644 --- a/src/filter/size.rs +++ b/src/filter/size.rs @@ -56,7 +56,8 @@ impl SizeFilter { _ => return None, }; - let size = quantity * multiplier; + let size = quantity.checked_mul(multiplier)?; + match limit_kind { "+" => Some(Self::Min(size)), "-" => Some(Self::Max(size)), @@ -216,4 +217,42 @@ mod tests { let f = SizeFilter::from_string("+1K").unwrap(); assert!(f.is_within(1000)); } + + #[test] + fn ensure_size_multiplication_overflow_returns_error() { + let invalid = [ + "+18446744073709551615k", + "-18446744073709551615m", + "18446744073709551615g", + "+18446744073709551615ti", + "-18446744073709551615tib", + ]; + + for input in invalid { + assert!( + SizeFilter::from_string(input).is_err(), + "Expected {input:?} to fail due to overflow" + ); + } + } + + #[test] + fn ensure_size_multiplication_boundary() { + let max_valid = u64::MAX / KILO; + + assert_eq!( + SizeFilter::from_string(&format!("{max_valid}k")).unwrap(), + SizeFilter::Equals(max_valid * KILO) + ); + + assert!(SizeFilter::from_string(&format!("{}k", max_valid + 1)).is_err()); + } + + #[test] + fn ensure_max_u64_does_not_overflow() { + assert_eq!( + SizeFilter::from_string("18446744073709551615b").unwrap(), + SizeFilter::Equals(u64::MAX) + ); + } } From 7c885ef479a3f0c53299b328ad9b65abc3fe8ed3 Mon Sep 17 00:00:00 2001 From: parneetsingh022 Date: Tue, 27 Oct 2026 00:13:00 -0700 Subject: [PATCH 2/3] docs: added changelog entry for size filter overflow fix --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 67dbfc4..56b2e53 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -27,6 +27,7 @@ - Also fire the "search pattern contains a path separator" diagnostic for `--and` patterns, not only the primary positional pattern. `--and` patterns are matched against the file name just like the primary pattern, so a path separator in them silently returned zero results. See #1873. - Fix bug where passing "-" as a directory argument didn't actually search that directory, see #849 (@Sean-Kenneth-Doherty). - Fix panic when `--changed-before`/`--changed-within` is given an out-of-range `@` Unix timestamp; the value is now rejected gracefully, see #2081 (@nikolauspschuetz). +- Fix integer overflow when parsing size constraints, rejecting values that exceed `u64::MAX` instead of panicking, see #2196 (@parneetsingh022). # 10.4.2 From 0b3249c58cbc9b980e11ac3781938e9031db1a0a Mon Sep 17 00:00:00 2001 From: parneetsingh022 Date: Tue, 27 Oct 2026 16:03:37 -0700 Subject: [PATCH 3/3] docs: move --size overflow changelog entry to Unreleased section --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 56b2e53..c1accea 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ - Don't incorrectly escape newlines in error messages, see #2104 - Restore jemalloc as default allocator on supported systems - Fix the `cargo binstall` release URL, which named the crate (`fd-find`) instead of the binary (`fd`) and fell back to a third-party mirror +- Fix integer overflow when parsing size constraints, rejecting values that exceed `u64::MAX` instead of panicking, see #2196 (@parneetsingh022). # 10.5.0 @@ -27,7 +28,6 @@ - Also fire the "search pattern contains a path separator" diagnostic for `--and` patterns, not only the primary positional pattern. `--and` patterns are matched against the file name just like the primary pattern, so a path separator in them silently returned zero results. See #1873. - Fix bug where passing "-" as a directory argument didn't actually search that directory, see #849 (@Sean-Kenneth-Doherty). - Fix panic when `--changed-before`/`--changed-within` is given an out-of-range `@` Unix timestamp; the value is now rejected gracefully, see #2081 (@nikolauspschuetz). -- Fix integer overflow when parsing size constraints, rejecting values that exceed `u64::MAX` instead of panicking, see #2196 (@parneetsingh022). # 10.4.2