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.
This commit is contained in:
Jason Miller 2021-04-18 11:07:10 +02:00 committed by GitHub
parent fc808f2aa8
commit 421a2512f7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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())?;