Check sample coordinate bounds (closes: #24)

This commit is contained in:
Paul van Tilburg 2022-06-06 19:51:07 +02:00
parent 2b23885692
commit 712b3a9acf
Signed by: paul
GPG Key ID: C6DE073EDA9EEC4D
1 changed files with 3 additions and 0 deletions

View File

@ -356,6 +356,9 @@ fn sample<I: GenericImageView<Pixel = Rgba<u8>>>(
let (x, y) = coords;
let width = image.width() / count;
let height = image.height();
if x > width || y > height {
return Err(Error::OutOfBoundCoords(x, y));
}
let max_sample_width = (width - x).min(MAP_SAMPLE_SIZE[0]);
let max_sample_height = (height - y).min(MAP_SAMPLE_SIZE[1]);
let mut samples = Vec::with_capacity(count as usize);