From 421a2512f7d602bd0d4413d72b438e5891c94b86 Mon Sep 17 00:00:00 2001 From: Jason Miller Date: Sun, 18 Apr 2021 11:07:10 +0200 Subject: [PATCH] Hash collision using the same quality level and incorrect quality for WebP (#1431) * fix: webp quality level mismatch * fix: hash collision using the same image ops Using the same image operations, but for different formats, e.g. `.jpg` and `.webp`, produced the same hash. To differentiate between these, the image extension is added to the hash. --- components/imageproc/src/lib.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/components/imageproc/src/lib.rs b/components/imageproc/src/lib.rs index 99b6abb9..2ce000fe 100644 --- a/components/imageproc/src/lib.rs +++ b/components/imageproc/src/lib.rs @@ -207,6 +207,7 @@ impl Hash for Format { }; hasher.write_u8(q); + hasher.write(self.extension().as_bytes()); } } @@ -316,7 +317,7 @@ impl ImageOp { Format::WebP(q) => { let encoder = webp::Encoder::from_image(&img); let memory = match q { - Some(q) => encoder.encode(q as f32 / 100.), + Some(q) => encoder.encode(q as f32), None => encoder.encode_lossless(), }; f.write_all(&memory.as_bytes())?;