From c60ea98b73dbc6afc4a912df60693e4b19da5ce4 Mon Sep 17 00:00:00 2001 From: MohitMaliFtechiz Date: Wed, 8 Jan 2025 15:35:47 +0530 Subject: [PATCH] Fixed the issue where opening a random article caused the application to crash. * The issue occurred in the Play Store variant, specifically with the copy/move functionality for ZIM files. After copying or moving a ZIM file, the application attempts to open it in the reader. However, if the application tries to open a split ZIM file with only one chunk, it throws an error indicating that the file is not a valid ZIM file (which is expected, as not all ZIM chunks have been copied/moved). When this error occurs, the menu buttons remain enabled, allowing the user to interact with them. If the user then attempts to open a random article, the application enters an infinite loop and crashes. To resolve this, we now disable the menu controls whenever an error occurs while opening a ZIM file, preventing the user from using them in such scenarios. --- .../org/kiwix/kiwixmobile/core/main/CoreReaderFragment.kt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/core/src/main/java/org/kiwix/kiwixmobile/core/main/CoreReaderFragment.kt b/core/src/main/java/org/kiwix/kiwixmobile/core/main/CoreReaderFragment.kt index a2edbc7f8..26ca13f03 100644 --- a/core/src/main/java/org/kiwix/kiwixmobile/core/main/CoreReaderFragment.kt +++ b/core/src/main/java/org/kiwix/kiwixmobile/core/main/CoreReaderFragment.kt @@ -1735,6 +1735,10 @@ abstract class CoreReaderFragment : mainMenu?.onFileOpened(urlIsValid()) setUpBookmarks(zimFileReader) } ?: kotlin.run { + // If the ZIM file is not opened properly (especially for ZIM chunks), exit the book to + // disable all controls for this ZIM file. This prevents potential crashes. + // See issue #4161 for more details. + exitBook() requireActivity().toast(R.string.error_file_invalid, Toast.LENGTH_LONG) } }