diff --git a/crates/fetch/src/lib.rs b/crates/fetch/src/lib.rs index 07552e4bb3..8e1b8e7346 100644 --- a/crates/fetch/src/lib.rs +++ b/crates/fetch/src/lib.rs @@ -242,6 +242,7 @@ fn validate_files(files: &[FileSpec<'_>]) -> Result { if files.len() > 256 { return Err(DownloadError::Invalid("too many files".into())); } + // (names that differ only in case are one file on a case-insensitive file system) let mut seen = std::collections::HashSet::new(); let mut total = 0u64; for f in files { @@ -259,7 +260,7 @@ fn validate_files(files: &[FileSpec<'_>]) -> Result { || f.name.starts_with('.') || f.name.contains(['/', '\\', ':']) || f.name.chars().any(char::is_control) - || !seen.insert(f.name) + || !seen.insert(f.name.to_lowercase()) { return Err(DownloadError::Invalid("a filename must be a unique, ordinary filename".into())); } diff --git a/crates/fetch/src/tests.rs b/crates/fetch/src/tests.rs index 5144bfc097..d144e08d29 100644 --- a/crates/fetch/src/tests.rs +++ b/crates/fetch/src/tests.rs @@ -425,3 +425,10 @@ fn hostile_file_specs_are_rejected_before_touching_disk() { assert!(!dir.exists()); } } + +#[test] +fn names_differing_only_in_case_are_one_file() { + let spec = |name| FileSpec { name, size: Some(1), sha256: None, max: 1 }; + assert!(super::validate_files(&[spec("Model.bin")]).is_ok()); + assert!(super::validate_files(&[spec("Model.bin"), spec("model.BIN")]).is_err()); +} diff --git a/crates/raster/src/blur.rs b/crates/raster/src/blur.rs index 9fefea9ca2..c038340a38 100644 --- a/crates/raster/src/blur.rs +++ b/crates/raster/src/blur.rs @@ -49,8 +49,15 @@ fn box_row(row: &mut [T], tmp: &mut Vec, r: usize) { let last = w - 1; let inv = 1.0 / (2 * r + 1) as f32; let mut acc = T::zero(); - for i in 0..=2 * r { - acc = acc.madd(s[i.saturating_sub(r).min(last)], 1.0); + // the window [-r, r] with clamped edges: r copies of the first pixel, the pixels 0..=min(r, last), then the + // last pixel for each offset past it (O(w), not O(r), however large the radius) + acc = acc.madd(s[0], r as f32); + for v in &s[..=r.min(last)] { + acc = acc.madd(*v, 1.0); + } + // only when the window reaches past the last pixel: a NaN there must not poison a row it isn't in + if r > last { + acc = acc.madd(s[last], (r - last) as f32); } for x in 0..w { row[x] = T::zero().madd(acc, inv); @@ -177,6 +184,14 @@ pub fn gaussian_taps(img: &Image, taps: &[f32]) -> Image { #[cfg(test)] mod tests { + #[test] + fn a_non_finite_last_pixel_stays_out_of_windows_that_do_not_reach_it() { + let mut row = [1.0f32; 8]; + row[7] = f32::NAN; + box_row(&mut row, &mut Vec::new(), 2); + assert!(row[..5].iter().all(|v| v.is_finite()), "{row:?}"); + } + #[test] fn fir_gaussian_has_bounded_finite_taps_for_hostile_sigmas() { for sigma in [f32::NAN, f32::NEG_INFINITY, f32::INFINITY, f32::MAX, -5.0, 0.0, 0.1, 4.0] { @@ -277,4 +292,18 @@ mod tests { let var: f32 = b.data.iter().enumerate().map(|(i, v)| v * ((i as f32 - 100.0).powi(2))).sum(); assert!((var.sqrt() - sigma).abs() / sigma < 0.1, "{}", var.sqrt()); } + + #[test] + fn box_row_matches_the_clamped_window_sum_for_radii_past_the_row() { + for (w, r) in [(1usize, 1usize), (5, 1), (5, 4), (5, 5), (5, 9), (7, 3)] { + let mut row: Vec = (0..w).map(|i| (i * i + 1) as f32).collect(); + let want: Vec = (0..w as isize) + .map(|x| (-(r as isize)..=r as isize).map(|j| row[(x + j).clamp(0, w as isize - 1) as usize]).sum::() / (2 * r + 1) as f32) + .collect(); + box_row(&mut row, &mut Vec::new(), r); + for (a, b) in row.iter().zip(&want) { + assert!((a - b).abs() < 1e-3, "w {w} r {r}: {a} vs {b}"); + } + } + } } diff --git a/xtask/src/stats.rs b/xtask/src/stats.rs index f40b1300ac..233c634b92 100644 --- a/xtask/src/stats.rs +++ b/xtask/src/stats.rs @@ -18,7 +18,8 @@ fn walk(dir: &Path, c: &mut Counts) { let p = e.path(); let name = e.file_name(); let name = name.to_string_lossy(); - if p.is_dir() { + // (a link to a directory is not followed: a cycle of links would be walked without end) + if e.file_type().is_ok_and(|t| t.is_dir()) { // Nested fuzz workspaces and build output are not part of the crate. if name != "target" && name != "fuzz" && !name.starts_with('.') { walk(&p, c);