From 4ec5a600bb884d3f5b71640c85ee8d1492353597 Mon Sep 17 00:00:00 2001 From: MegaBrutal <code+git@megabrutal.com> Date: Sun, 26 Jun 2022 01:30:00 +0200 Subject: [PATCH] Return error on too much data --- src/main.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main.rs b/src/main.rs index f46e88f..c9c48b8 100644 --- a/src/main.rs +++ b/src/main.rs @@ -11,6 +11,7 @@ use actix_web::http::StatusCode; use image::{ImageBuffer, ColorType, Rgb, RgbImage, write_buffer_with_format}; use image::ImageOutputFormat::Png; use image::imageops::{FilterType, resize}; +use image::error::{LimitError, LimitErrorKind}; #[derive(Debug)] @@ -28,7 +29,7 @@ impl ResponseError for ImageError { } fn error_response(&self) -> HttpResponse<BoxBody> { - HttpResponse::InternalServerError().finish() + HttpResponse::InternalServerError().body(format!("{}\n", &self)) } } @@ -74,7 +75,7 @@ fn make_png(dim_x: u32, dim_y: u32, scale: u32, data: &mut dyn Iterator<Item = u let mut pixels = img.pixels_mut(); for sp in ToRgbIter::new(data) { - let mut dp = pixels.next().unwrap(); + let mut dp = pixels.next().ok_or(ImageError(image::ImageError::Limits(LimitError::from_kind(LimitErrorKind::DimensionError))))?; println!("{:?}", sp); dp.0 = sp.0; } -- 2.34.1