Repository: qarmin/czkawka (language: rust)

Issue:
strange bug that program appear to be hang after scan completed or stopped
**Bug Description**
latest github source, build following the guide. (i had been doing this since long time ago and it was always working correctly until recently).
during hashing stage, if user stop the hashing, or even hashing completed, for large library, the program will appear like hang, but you can still move the czkawka dialog box.

**Steps to reproduce:**
<!-- Please describe what you expected to see and what you saw instead. Also include screenshots or screencasts if needed. -->
just scan images for large library, and then stop.
![image](https://github.com/qarmin/czkawka/assets/1291771/fb49bba1-6c3f-42b8-96c0-549b0389bcff)
i had been stuck in this interface for more than 12 hours, htop show there is no activity, no high CPU usage nor IO usage.

![image](https://github.com/qarmin/czkawka/assets/1291771/6bc5ae23-fb06-4673-91a9-a9dff37044fc)



```
    Finished release [optimized] target(s) in 0.21s
     Running `target/release/czkawka_gui`
16:43:58.849 [INFO] czkawka_core::common: App version: 7.0.0, release mode, rust 1.76.0 (2024-02-04), os Ubuntu 23.10 [x86_64 64-bit], 6 cpu/threads

(czkawka_gui:4566): Gtk-WARNING **: 16:43:58.880: No IM module matching GTK_IM_MODULE=fcitx found
16:43:59.180 [INFO] czkawka_gui: Set thread number to 6

(czkawka_gui:4566): IBUS-WARNING **: 16:43:59.229: Unable to connect to ibus: Could not connect: Connection refused
16:44:05.600 [INFO] czkawka_core::similar_images: find_similar_images
thread '<unnamed>' panicked at czkawka_core/src/similar_images.rs:393:21:
internal error: entered unreachable code
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

```



**System**

- Czkawka/Krokiet version: 7.0.0
- OS version: Ubuntu 23.10 (was ok before)
- Installation method: compilation from latest source

i was thinking that maybe my Linux OS corrupted, so i installed a fresh new Ubuntu.

then i think maybe my database corrupted, i deleted the database in .cache/czkawka folder.

but still the result is same.



Discussion / hints:
Crash happens in this code
https://github.com/qarmin/czkawka/blob/e5a0219bc92db67907923f181b5212526f6b77c5/czkawka_core/src/similar_images.rs#L372-L396

and is caused by using here image with unknown extension - this situation should never happens, because images with known extensions should be used in this code, but somehow happened.
great, since you had traced the issue, i believe you will be able to fix it soon, thanks!

Fix patch:
diff --git a/czkawka_core/src/similar_images.rs b/czkawka_core/src/similar_images.rs
index d652de795..67440c462 100644
--- a/czkawka_core/src/similar_images.rs
+++ b/czkawka_core/src/similar_images.rs
@@ -279,6 +279,12 @@ impl SimilarImages {
         let (progress_thread_handle, progress_thread_run, atomic_counter, check_was_stopped) =
             prepare_thread_handler_common(progress_sender, 1, 2, non_cached_files_to_check.len(), CheckingMethod::None, self.common_data.tool_type);
 
+        // Throw out images with not proper type - TODO why this happens, only broken cache?
+        let non_cached_files_to_check = non_cached_files_to_check
+            .into_iter()
+            .filter(|(_, file_entry)| file_entry.image_type != ImageType::Unknown)
+            .collect::<BTreeMap<_, _>>();
+
         debug!("hash_images - start hashing images");
         let mut vec_file_entry: Vec<ImagesEntry> = non_cached_files_to_check
             .into_par_iter()


Test patch: