From e2d4fd8bde7817b68bad169c2a6e6c7f09f97f83 Mon Sep 17 00:00:00 2001 From: Anh Dinh Date: Thu, 13 Aug 2026 13:14:23 +0300 Subject: [PATCH 1/2] Fix integer overflow --- src/config.rs | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/config.rs b/src/config.rs index 0db951f..dffa234 100644 --- a/src/config.rs +++ b/src/config.rs @@ -32,8 +32,9 @@ impl Config { "Parent zoom level number needs to be bigger than the input image zoom level." ) } - if indexforzoom > (1 << ((parentzoomlevelvalue - zoomlevel) * 2)) - 1 { - panic!("indexforzoom value is larger than allowed.") + let max_allowed = (1u64 << ((parentzoomlevelvalue - zoomlevel) * 2)) - 1; + if (indexforzoom as u64) > max_allowed { + panic!("indexforzoom value is larger than allowed."); } Config { tilesize, @@ -287,6 +288,14 @@ mod tests { assert_eq!(config.targetrangetoslice, 0..=1023); } + #[test] + // allow indexforzoom values greater than 63 when parent zoom is much larger + fn sub_image_large_index() { + let config = Config::new(256, 3, Some(7), 212, None, None, Some(2)); + assert_eq!(config.zoomrangetoslice, 3..=3); + assert_eq!(config.targetrangetoslice, 0..=63); + } + #[test] #[should_panic] // should panic if zoomlevel is larger than parentzoomlevel From 3174f71b43a85ea72b3fc68a2a31e14e656eb0e7 Mon Sep 17 00:00:00 2001 From: Anh Dinh Date: Thu, 13 Aug 2026 14:21:21 +0300 Subject: [PATCH 2/2] Clippying --- src/config.rs | 2 +- src/image.rs | 11 ++++------- src/main.rs | 4 ++-- 3 files changed, 7 insertions(+), 10 deletions(-) diff --git a/src/config.rs b/src/config.rs index dffa234..b0ec673 100644 --- a/src/config.rs +++ b/src/config.rs @@ -114,7 +114,7 @@ impl Config { } } - pub fn resize_range(&self, img: &DynamicImage) -> Vec<(TileImage, u8)> { + pub fn resize_range(&self, img: &DynamicImage) -> Vec<(TileImage<'_>, u8)> { as Clone>::clone(&self.zoomrangetoslice) .into_par_iter() .map(|x: u8| { diff --git a/src/image.rs b/src/image.rs index 119050f..dee2558 100644 --- a/src/image.rs +++ b/src/image.rs @@ -10,18 +10,15 @@ pub struct TileImage<'c> { } impl<'c> TileImage<'c> { - pub fn slice_tiles(&self, index: u8) -> Vec { + pub fn slice_tiles(&self, index: u8) -> Vec> { let tiles_per_row = 1 << index; let morton_idx_max = tiles_per_row * tiles_per_row; let tileimage_coord: (u16, u16) = match &self.config.parentzoomlevel { None => (0, 0), - Some(parentzoomlevel) => { - if parentzoomlevel > &self.config.zoomlevel { - coord_of(self.config.indexforzoom.into()) - } else { - (0, 0) - } + Some(parentzoomlevel) if parentzoomlevel > &self.config.zoomlevel => { + coord_of(self.config.indexforzoom.into()) } + _ => (0, 0), }; let output_level = match &self.config.parentzoomlevel { None => index, diff --git a/src/main.rs b/src/main.rs index 7d5af58..89dc297 100644 --- a/src/main.rs +++ b/src/main.rs @@ -75,7 +75,7 @@ fn main() { if args.preset.is_some() && &args.tileformat != "png" { eprintln!( "Error: The --preset argument cannot be used with --tileformat set to '{}'", - &args.tileformat + args.tileformat ); std::process::exit(2); } @@ -136,7 +136,7 @@ fn main() { let path = &args.output_dir.join(format!( "{name}.{fmt}", name = tile.name, - fmt = &args.tileformat + fmt = args.tileformat )); img.to_image().save(path).unwrap(); }