mirror of
https://github.com/Syfaro/fuzzysearch.git
synced 2024-11-23 15:22:31 +00:00
Handle corrupted images.
This commit is contained in:
parent
0b42564c5e
commit
41a993d0b1
26
src/main.rs
26
src/main.rs
@ -122,16 +122,22 @@ async fn process_submission(
|
|||||||
.bytes()
|
.bytes()
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
let hasher = img_hash::HasherConfig::with_bytes_type::<[u8; 8]>()
|
let num = if let Ok(image) = image::load_from_memory(&data) {
|
||||||
.hash_alg(img_hash::HashAlg::Gradient)
|
let hasher = img_hash::HasherConfig::with_bytes_type::<[u8; 8]>()
|
||||||
.hash_size(8, 8)
|
.hash_alg(img_hash::HashAlg::Gradient)
|
||||||
.preproc_dct()
|
.hash_size(8, 8)
|
||||||
.to_hasher();
|
.preproc_dct()
|
||||||
let image = image::load_from_memory(&data)?;
|
.to_hasher();
|
||||||
let hash = hasher.hash_image(&image);
|
let hash = hasher.hash_image(&image);
|
||||||
let mut bytes: [u8; 8] = [0; 8];
|
let mut bytes: [u8; 8] = [0; 8];
|
||||||
bytes.copy_from_slice(hash.as_bytes());
|
bytes.copy_from_slice(hash.as_bytes());
|
||||||
let num = i64::from_be_bytes(bytes);
|
let num = i64::from_be_bytes(bytes);
|
||||||
|
Some(num)
|
||||||
|
} else {
|
||||||
|
println!("Unable to decode image on submission {}", sub.id);
|
||||||
|
|
||||||
|
None
|
||||||
|
};
|
||||||
|
|
||||||
let mut hasher = Sha256::new();
|
let mut hasher = Sha256::new();
|
||||||
hasher.update(&data);
|
hasher.update(&data);
|
||||||
|
Loading…
Reference in New Issue
Block a user