Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed: Version 3.9.1 was experiencing occasional crashes when setting the SuggestionSearcher. #3649

Merged
merged 1 commit into from
Feb 14, 2024

Conversation

MohitMaliFtechiz
Copy link
Collaborator

@MohitMaliFtechiz MohitMaliFtechiz commented Jan 2, 2024

Fixes #3643
The crashes occurred in the Play Store version due to insufficient permissions for opening a file via fileDescriptor. To address this issue, we have modified the implementation to use the file instead of fileDescriptor. This adjustment ensures smooth operation in the non-Play Store version where we have permission to open a file via its path. In the Play Store version, it will display a proper error message to the user, preventing errors thrown by libkiwix.

@MohitMaliFtechiz MohitMaliFtechiz marked this pull request as draft January 2, 2024 13:56
Copy link

codecov bot commented Jan 2, 2024

Codecov Report

Attention: 15 lines in your changes are missing coverage. Please review.

Comparison is base (1f07863) 51.70% compared to head (2875037) 51.69%.

Files Patch % Lines
...bile/nav/destination/reader/KiwixReaderFragment.kt 0.00% 15 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##               main    #3649      +/-   ##
============================================
- Coverage     51.70%   51.69%   -0.02%     
- Complexity     1241     1242       +1     
============================================
  Files           288      288              
  Lines         10841    10851      +10     
  Branches       1451     1454       +3     
============================================
+ Hits           5605     5609       +4     
- Misses         4282     4289       +7     
+ Partials        954      953       -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@MohitMaliFtechiz MohitMaliFtechiz marked this pull request as ready for review January 2, 2024 16:03
@kelson42
Copy link
Collaborator

kelson42 commented Jan 2, 2024

@MohitMaliFtechiz You seems to imply that the root cause of these crash is in libkiwix but you propose a patch in Kiwix. To me this seems incoherent.

What is the precise and exact root cause of these crash scenarios?

@MohitMaliFtechiz
Copy link
Collaborator Author

@MohitMaliFtechiz You seems to imply that the root cause of these crash is in libkiwix but you propose a patch in Kiwix. To me this seems incoherent.
What is the precise and exact root cause of these crash scenarios?

@kelson42, There are a few occurrences detected by playstore, this error is happening on the Play Store which has limited access to storage. We are experiencing the same issue with the same logs in #3636. Here in Play Store variant, since there are a few occurrences, it might be possible only a few users are using this feature of our application. When there is a permission-related issue openAssetFileDescriptor throws the SecurityException.

So to address this problem we have improved the exception handling on the Android side, and improved our getAssetFileDescriptorFromUri method, to catch the security exception thrown by this method when the URI has insufficient permission to open the fileDescriptor from it.
Now, we have improved this on the Android side to catch the security exception if there is a permission-related issue with the URI, and the other part we are trying to fix in #3636. Let me know, if still anything is unclear or if I missed something to explain.

@kelson42
Copy link
Collaborator

kelson42 commented Jan 5, 2024

@MohitMaliFtechiz I think the root problem is not well understand so far and I have therefore concern to merge a PR which might simply hide the issue.

@gouri-panda
Copy link
Collaborator

@kelson42 I think @MohitMaliFtechiz can't produce this bug and based on the log the playstore provided @MohitMaliFtechiz is trying to solve them. Both this and #3636 might solve this problem. If there's no error in the playstore in the future we'll guess it solved. @MohitMaliFtechiz am i right?

@MohitMaliFtechiz
Copy link
Collaborator Author

@kelson42 I think @MohitMaliFtechiz can't produce this bug and based on the log the playstore provided @MohitMaliFtechiz is trying to solve them. Both this and #3636 might solve this problem. If there's no error in the playstore in the future we'll guess it solved. @MohitMaliFtechiz am i right?

@gouri-panda Your explanation is quite right here. I want to add one point here, This error happens when the fileDesciptor does not have the necessary permission then libkiwix throw this error, and @mgautierfr confirms #3636 (comment) how libkiwix using the fileDescriptor so here before passing fileDescriptor to libkiwix, we should also check the fileDescriptor permission via path so that libkiwix does not throw this type of error.

@MohitMaliFtechiz
Copy link
Collaborator Author

@gouri-panda, I have added the check on fileDescriptor which checks if libkiwix can open the fileDescriptor or not before passing it to the libkiwix to avoid the crash thrown by the libkiwix. However, if we succeed in implementing #3636 then we can remove this check in the future but for now, we need this to avoid application crash.

@gouri-panda
Copy link
Collaborator

@MohitMaliFtechiz Thanks! I'll look into that.

@kelson42
Copy link
Collaborator

#3636 is about opening ZIM files via filehandler. This should not happen in Kiwix (only in custom apps). So what is the root cause of the crashes we have here?

@MohitMaliFtechiz
Copy link
Collaborator Author

MohitMaliFtechiz commented Jan 15, 2024

@kelson42 We are using deep linking in our application for directly opening the externally downloaded ZIM file. We had an see issue where we were not able to open the externally downloaded ZIM file for that issue we had introduced the opening ZIM file by fd see.

@kelson42
Copy link
Collaborator

or that issue we had introduced the opening ZIM file by fd see.

Are you sure the title suggestions work in this scenario?!? because our investigation with @mgautierfr then to show that it's impossible from it on armv8 to open properly a new filehandler for the Xapian

@MohitMaliFtechiz
Copy link
Collaborator Author

MohitMaliFtechiz commented Jan 15, 2024

@kelson42 all functionalities are working fine in the non-playstore variant including suggestions search. However, in play store variant, it is showing the Failed to open file Please try looking for this file in the Device Tab of your Library toast message since in this variant we don't have the access

I got a new pixel 2 device today, and I have tested this scenario with that device and I can reproduce the bug on that device with the same logs.

*** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
2024-01-15 15:03:48.403   374-374   DEBUG                   pid-374                              A  Build fingerprint: 'google/lynx/lynx:14/UQ1A.231205.015/11084887:user/release-keys'
2024-01-15 15:03:48.403   374-374   DEBUG                   pid-374                              A  Revision: 'MP1.0'
2024-01-15 15:03:48.403   374-374   DEBUG                   pid-374                              A  ABI: 'arm64'
2024-01-15 15:03:48.403   374-374   DEBUG                   pid-374                              A  Timestamp: 2024-01-15 15:03:48.266380955+0530
2024-01-15 15:03:48.403   374-374   DEBUG                   pid-374                              A  Process uptime: 18s
2024-01-15 15:03:48.403   374-374   DEBUG                   pid-374                              A  Cmdline: org.kiwix.kiwixmobile
2024-01-15 15:03:48.403   374-374   DEBUG                   pid-374                              A  pid: 32558, tid: 32558, name: wix.kiwixmobile  >>> org.kiwix.kiwixmobile <<<
2024-01-15 15:03:48.403   374-374   DEBUG                   pid-374                              A  uid: 10372
2024-01-15 15:03:48.403   374-374   DEBUG                   pid-374                              A  tagged_addr_ctrl: 0000000000000001 (PR_TAGGED_ADDR_ENABLE)
2024-01-15 15:03:48.403   374-374   DEBUG                   pid-374                              A  signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x0000000000000000
2024-01-15 15:03:48.403   374-374   DEBUG                   pid-374                              A  Cause: null pointer dereference
2024-01-15 15:03:48.403   374-374   DEBUG                   pid-374                              A      x0  0000000000000000  x1  000000005c000000  x2  b40000727b87d380  x3  000000000000004a
2024-01-15 15:03:48.403   374-374   DEBUG                   pid-374                              A      x4  000000000000004a  x5  656c646e61486576  x6  656c646e61486576  x7  00000071ba4a8ff4
2024-01-15 15:03:48.403   374-374   DEBUG                   pid-374                              A      x8  0c19bb479d82c700  x9  0c19bb479d82c700  x10 00000071bae03620  x11 0000007fc2bd4100
2024-01-15 15:03:48.403   374-374   DEBUG                   pid-374                              A      x12 0000000000000001  x13 000000712c8e6cd4  x14 00000000000000a3  x15 0000007466c42a70
2024-01-15 15:03:48.403   374-374   DEBUG                   pid-374                              A      x16 0000000000000001  x17 000000745f8e4900  x18 00000074661d6000  x19 b40000739b878530
2024-01-15 15:03:48.403   374-374   DEBUG                   pid-374                              A      x20 0000007fc2bd437c  x21 0000007fc2bd4378  x22 000000712caf3c62  x23 0000000000002070
2024-01-15 15:03:48.403   374-374   DEBUG                   pid-374                              A      x24 00000071ba9b0c80  x25 0000007fc2bd4390  x26 0000007fc2bd43a8  x27 0000007fc2bd4390
2024-01-15 15:03:48.403   374-374   DEBUG                   pid-374                              A      x28 0000007fc2bd4290  x29 0000007fc2bd4270
2024-01-15 15:03:48.403   374-374   DEBUG                   pid-374                              A      lr  00000071b5f2f464  sp  0000007fc2bd4230  pc  00000071b5f2f464  pst 0000000060001000
2024-01-15 15:03:48.403   374-374   DEBUG                   pid-374                              A  46 total frames
2024-01-15 15:03:48.403   374-374   DEBUG                   pid-374                              A  backtrace:
2024-01-15 15:03:48.403   374-374   DEBUG                   pid-374                              A        #00 pc 0000000000025464  /data/app/~~47c46jMWHkPfuKlhZIWq7A==/org.kiwix.kiwixmobile-QcJwRLIuFEQJJcKwmYHhGw==/base.apk!libzim_wrapper.so (offset 0x119e000) (Java_org_kiwix_libzim_SuggestionSearcher_setNativeSearcher+112) (BuildId: 6c0d6ee977af86c7d817e067ec4176543043faa4)
2024-01-15 15:03:48.403   374-374   DEBUG                   pid-374                              A        #01 pc 0000000000355830  /apex/com.android.art/lib64/libart.so (art_quick_generic_jni_trampoline+144) (BuildId: 735f12f804f88d62a2cb437261076ff7)
2024-01-15 15:03:48.403   374-374   DEBUG                   pid-374                              A        #02 pc 00000000005ba6b0  /apex/com.android.art/lib64/libart.so (nterp_helper+4016) (BuildId: 735f12f804f88d62a2cb437261076ff7)
2024-01-15 15:03:48.404   374-374   DEBUG                   pid-374                              A        #03 pc 0000000000242c62  /data/app/~~47c46jMWHkPfuKlhZIWq7A==/org.kiwix.kiwixmobile-QcJwRLIuFEQJJcKwmYHhGw==/oat/arm64/base.vdex (org.kiwix.libzim.SuggestionSearcher.<init>+6)
2024-01-15 15:03:48.404   374-374   DEBUG                   pid-374                              A        #04 pc 00000000005ba654  /apex/com.android.art/lib64/libart.so (nterp_helper+3924) (BuildId: 735f12f804f88d62a2cb437261076ff7)
2024-01-15 15:03:48.404   374-374   DEBUG                   pid-374                              A        #05 pc 00000000002200fa  /data/app/~~47c46jMWHkPfuKlhZIWq7A==/org.kiwix.kiwixmobile-QcJwRLIuFEQJJcKwmYHhGw==/oat/arm64/base.vdex (org.kiwix.kiwixmobile.core.reader.ZimFileReader.<init>+34)
2024-01-15 15:03:48.404   374-374   DEBUG                   pid-374                              A        #06 pc 00000000005bad58  /apex/com.android.art/lib64/libart.so (nterp_helper+5720) (BuildId: 735f12f804f88d62a2cb437261076ff7)
2024-01-15 15:03:48.404   374-374   DEBUG                   pid-374                              A        #07 pc 000000000021fad4  /data/app/~~47c46jMWHkPfuKlhZIWq7A==/org.kiwix.kiwixmobile-QcJwRLIuFEQJJcKwmYHhGw==/oat/arm64/base.vdex (org.kiwix.kiwixmobile.core.reader.ZimFileReader$Factory$Impl.create+72)
2024-01-15 15:03:48.404   374-374   DEBUG                   pid-374                              A        #08 pc 00000000005bb474  /apex/com.android.art/lib64/libart.so (nterp_helper+7540) (BuildId: 735f12f804f88d62a2cb437261076ff7)
2024-01-15 15:03:48.404   374-374   DEBUG                   pid-374                              A        #09 pc 0000000000214508  /data/app/~~47c46jMWHkPfuKlhZIWq7A==/org.kiwix.kiwixmobile-QcJwRLIuFEQJJcKwmYHhGw==/oat/arm64/base.vdex (org.kiwix.kiwixmobile.core.main.CoreReaderFragment.openAndSetInContainer$default+176)
2024-01-15 15:03:48.404   374-374   DEBUG                   pid-374                              A        #10 pc 00000000005b9734  /apex/com.android.art/lib64/libart.so (nterp_helper+52) (BuildId: 735f12f804f88d62a2cb437261076ff7)
2024-01-15 15:03:48.404   374-374   DEBUG                   pid-374                              A        #11 pc 000000000021485a  /data/app/~~47c46jMWHkPfuKlhZIWq7A==/org.kiwix.kiwixmobile-QcJwRLIuFEQJJcKwmYHhGw==/oat/arm64/base.vdex (org.kiwix.kiwixmobile.core.main.CoreReaderFragment.openZimFile$default+114)
2024-01-15 15:03:48.404   374-374   DEBUG                   pid-374                              A        #12 pc 00000000005b9734  /apex/com.android.art/lib64/libart.so (nterp_helper+52) (BuildId: 735f12f804f88d62a2cb437261076ff7)
2024-01-15 15:03:48.404   374-374   DEBUG                   pid-374                              A        #13 pc 000000000023c5e2  /data/app/~~47c46jMWHkPfuKlhZIWq7A==/org.kiwix.kiwixmobile-QcJwRLIuFEQJJcKwmYHhGw==/oat/arm64/base.vdex (org.kiwix.kiwixmobile.nav.destination.reader.KiwixReaderFragment.onNewIntent$enumunboxing$+166)
2024-01-15 15:03:48.404   374-374   DEBUG                   pid-374                              A        #14 pc 00000000005bb474  /apex/com.android.art/lib64/libart.so (nterp_helper+7540) (BuildId: 735f12f804f88d62a2cb437261076ff7)
2024-01-15 15:03:48.404   374-374   DEBUG                   pid-374                              A        #15 pc 0000000000217fbe  /data/app/~~47c46jMWHkPfuKlhZIWq7A==/org.kiwix.kiwixmobile-QcJwRLIuFEQJJcKwmYHhGw==/oat/arm64/base.vdex (org.kiwix.kiwixmobile.core.main.NavigationHostFragment.onNewIntent$enumunboxing$+134)
2024-01-15 15:03:48.404   374-374   DEBUG                   pid-374                              A        #16 pc 00000000005bb474  /apex/com.android.art/lib64/libart.so (nterp_helper+7540) (BuildId: 735f12f804f88d62a2cb437261076ff7)
2024-01-15 15:03:48.404   374-374   DEBUG                   pid-374                              A        #17 pc 0000000000210650  /data/app/~~47c46jMWHkPfuKlhZIWq7A==/org.kiwix.kiwixmobile-QcJwRLIuFEQJJcKwmYHhGw==/oat/arm64/base.vdex (org.kiwix.kiwixmobile.core.main.CoreMainActivity.onNewIntent+132)
2024-01-15 15:03:48.404   374-374   DEBUG                   pid-374                              A        #18 pc 00000000005ba654  /apex/com.android.art/lib64/libart.so (nterp_helper+3924) (BuildId: 735f12f804f88d62a2cb437261076ff7)
2024-01-15 15:03:48.404   374-374   DEBUG                   pid-374                              A        #19 pc 000000000023843a  /data/app/~~47c46jMWHkPfuKlhZIWq7A==/org.kiwix.kiwixmobile-QcJwRLIuFEQJJcKwmYHhGw==/oat/arm64/base.vdex (org.kiwix.kiwixmobile.main.KiwixMainActivity.onNewIntent+10)
2024-01-15 15:03:48.404   374-374   DEBUG                   pid-374                              A        #20 pc 0000000000632ffc  /data/misc/apexdata/com.android.art/dalvik-cache/arm64/boot.oat (android.app.Instrumentation.callActivityOnNewIntent+156)
2024-01-15 15:03:48.404   374-374   DEBUG                   pid-374                              A        #21 pc 0000000000633124  /data/misc/apexdata/com.android.art/dalvik-cache/arm64/boot.oat (android.app.Instrumentation.callActivityOnNewIntent+180)
2024-01-15 15:03:48.404   374-374   DEBUG                   pid-374                              A        #22 pc 00000000006ffc7c  /data/misc/apexdata/com.android.art/dalvik-cache/arm64/boot.oat (android.app.ActivityThread.deliverNewIntents+396)
2024-01-15 15:03:48.404   374-374   DEBUG                   pid-374                              A        #23 pc 000000000071c548  /data/misc/apexdata/com.android.art/dalvik-cache/arm64/boot.oat (android.app.ActivityThread.handleNewIntent+312)
2024-01-15 15:03:48.404   374-374   DEBUG                   pid-374                              A        #24 pc 00000000008df4a0  /data/misc/apexdata/com.android.art/dalvik-cache/arm64/boot.oat (android.app.servertransaction.NewIntentItem.execute+144)
2024-01-15 15:03:48.404   374-374   DEBUG                   pid-374                              A        #25 pc 00000000008caf1c  /data/misc/apexdata/com.android.art/dalvik-cache/arm64/boot.oat (android.app.servertransaction.ActivityTransactionItem.execute+92)
2024-01-15 15:03:48.404   374-374   DEBUG                   pid-374                              A        #26 pc 000000000066716c  /data/misc/apexdata/com.android.art/dalvik-cache/arm64/boot.oat (android.app.servertransaction.TransactionExecutor.executeCallbacks+572)
2024-01-15 15:03:48.404   374-374   DEBUG                   pid-374                              A        #27 pc 0000000000666ec4  /data/misc/apexdata/com.android.art/dalvik-cache/arm64/boot.oat (android.app.servertransaction.TransactionExecutor.execute+708)
2024-01-15 15:03:48.404   374-374   DEBUG                   pid-374                              A        #28 pc 00000000006fae68  /data/misc/apexdata/com.android.art/dalvik-cache/arm64/boot.oat (android.app.ActivityThread$H.handleMessage+1464)
2024-01-15 15:03:48.404   374-374   DEBUG                   pid-374                              A        #29 pc 000000000096d298  /data/misc/apexdata/com.android.art/dalvik-cache/arm64/boot.oat (android.os.Handler.dispatchMessage+152)
2024-01-15 15:03:48.404   374-374   DEBUG                   pid-374                              A        #30 pc 0000000000970be4  /data/misc/apexdata/com.android.art/dalvik-cache/arm64/boot.oat (android.os.Looper.loopOnce+980)
2024-01-15 15:03:48.404   374-374   DEBUG                   pid-374                              A        #31 pc 0000000000970774  /data/misc/apexdata/com.android.art/dalvik-cache/arm64/boot.oat (android.os.Looper.loop+916)
2024-01-15 15:03:48.404   374-374   DEBUG                   pid-374                              A        #32 pc 00000000007127dc  /data/misc/apexdata/com.android.art/dalvik-cache/arm64/boot.oat (android.app.ActivityThread.main+2028)
2024-01-15 15:03:48.404   374-374   DEBUG                   pid-374                              A        #33 pc 000000000033f080  /apex/com.android.art/lib64/libart.so (art_quick_invoke_static_stub+640) (BuildId: 735f12f804f88d62a2cb437261076ff7)
2024-01-15 15:03:48.404   374-374   DEBUG                   pid-374                              A        #34 pc 00000000003884dc  /apex/com.android.art/lib64/libart.so (_jobject* art::InvokeMethod<(art::PointerSize)8>(art::ScopedObjectAccessAlreadyRunnable const&, _jobject*, _jobject*, _jobject*, unsigned long)+1588) (BuildId: 735f12f804f88d62a2cb437261076ff7)
2024-01-15 15:03:48.404   374-374   DEBUG                   pid-374                              A        #35 pc 0000000000387e98  /apex/com.android.art/lib64/libart.so (art::Method_invoke(_JNIEnv*, _jobject*, _jobject*, _jobjectArray*) (.__uniq.165753521025965369065708152063621506277)+32) (BuildId: 735f12f804f88d62a2cb437261076ff7)
2024-01-15 15:03:48.404   374-374   DEBUG                   pid-374                              A        #36 pc 000000000031b038  /data/misc/apexdata/com.android.art/dalvik-cache/arm64/boot.oat (art_jni_trampoline+120)
2024-01-15 15:03:48.404   374-374   DEBUG                   pid-374                              A        #37 pc 0000000000b60bb4  /data/misc/apexdata/com.android.art/dalvik-cache/arm64/boot.oat (com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run+116)
2024-01-15 15:03:48.404   374-374   DEBUG                   pid-374                              A        #38 pc 0000000000b6b738  /data/misc/apexdata/com.android.art/dalvik-cache/arm64/boot.oat (com.android.internal.os.ZygoteInit.main+3208)
2024-01-15 15:03:48.404   374-374   DEBUG                   pid-374                              A        #39 pc 000000000033f080  /apex/com.android.art/lib64/libart.so (art_quick_invoke_static_stub+640) (BuildId: 735f12f804f88d62a2cb437261076ff7)
2024-01-15 15:03:48.404   374-374   DEBUG                   pid-374                              A        #40 pc 00000000004e1ea8  /apex/com.android.art/lib64/libart.so (art::JValue art::InvokeWithVarArgs<_jmethodID*>(art::ScopedObjectAccessAlreadyRunnable const&, _jobject*, _jmethodID*, std::__va_list)+728) (BuildId: 735f12f804f88d62a2cb437261076ff7)
2024-01-15 15:03:48.404   374-374   DEBUG                   pid-374                              A        #41 pc 000000000057b930  /apex/com.android.art/lib64/libart.so (art::JNI<true>::CallStaticVoidMethodV(_JNIEnv*, _jclass*, _jmethodID*, std::__va_list)+156) (BuildId: 735f12f804f88d62a2cb437261076ff7)
2024-01-15 15:03:48.404   374-374   DEBUG                   pid-374                              A        #42 pc 00000000000daca8  /system/lib64/libandroid_runtime.so (_JNIEnv::CallStaticVoidMethod(_jclass*, _jmethodID*, ...)+104) (BuildId: 04347e608daaf447fe7dabf331c4ff21)
2024-01-15 15:03:48.404   374-374   DEBUG                   pid-374                              A        #43 pc 00000000000e6e2c  /system/lib64/libandroid_runtime.so (android::AndroidRuntime::start(char const*, android::Vector<android::String8> const&, bool)+860) (BuildId: 04347e608daaf447fe7dabf331c4ff21)
2024-01-15 15:03:48.404   374-374   DEBUG                   pid-374                              A        #44 pc 000000000000254c  /system/bin/app_process64 (main+1260) (BuildId: e8762c072e6c37bb8093e340cc42e9f2)
2024-01-15 15:03:48.404   374-374   DEBUG                   pid-374                              A        #45 pc 00000000000546e8  /apex/com.android.runtime/lib64/bionic/libc.so (__libc_init+104) (BuildId: 19c32900d9d702c303d2b4164fbba76c)

This PR resolved this crash and shows the Failed to open file Please try looking for this file in the Device Tab of your Library toast message since we does not have the permission to read the fd with the filePath.

@kelson42
Copy link
Collaborator

@MohitMaliFtechiz What you say here is in contradiction with what you say at #3636 where we fail there to open the Xapian index if ZIM file is open via fd even on a non playstore version. Please clarify.

@MohitMaliFtechiz
Copy link
Collaborator Author

MohitMaliFtechiz commented Jan 15, 2024

@kelson42 I think you misunderstood this, I have not said that this is not working on the non-playstore variant!! I have put the findings on #3636 for play store variant where we cannot directly access the storage.

Please see point number 4

@kelson42
Copy link
Collaborator

@MohitMaliFtechiz OK, but here we are trying to fix a problem on the PS version, so we should not use fd as this is simply not working! We should rewrite the code to stop to do - or stop allowing to do so - so for PS version.

@MohitMaliFtechiz
Copy link
Collaborator Author

so we should not use fd as this is simply not working!

@kelson42 In playstore variant we also have the limitation on accessing files from the fileSystem by using this feature. This PR validates the fd before passing it to the libkiwix whether it can open or not in libkiwix. Are you pointing to disabling this feature in the Play Store variant?

@kelson42
Copy link
Collaborator

kelson42 commented Jan 15, 2024

@MohitMaliFtechiz You should perfectly know already if a file can be open or not and how. You should not wait an error at the libkiwix level and treat it. The libkiwix does not trigger any random error. Please secure you use procedures which work properly. Otherwise open a bug in openzim/libkiwix. Both open-by-path and open-by-fd work perfectly fine is you understand them. You don't treat the problem at the root and this is what annoys me here.

@MohitMaliFtechiz
Copy link
Collaborator Author

@kelson42 I understand your concern, I also try to make sure every feature works fine on every device, and for that, I test all functionality on different devices with different architectures.

@MohitMaliFtechiz You should perfectly know already if a file can be open or not and how. You should not wait for an error at the libkiwix level and treat it. The libkiwix does not trigger any random error. Please secure you use procedures which work properly.

Most of the things are clear now after a conversation with @mgautierfr in #3628 and in this PR I am using the same way for validating the fd before opening the ZIM file in libkiwix to avoid this type of crash, and yes libkiwix is triggering the genuine error as libkiwix using the path to open fd for properly work with xapian. But for the PS variant, we can not do it.

Both open-by-path and open-by-fd work perfectly fine is you understand them.

Yes, I understand how these functions are working they both need access to the file path to properly work with the Xapian and in the PS version we have this limitation that is why we are encountering this type of problem. But now we are not waiting for libkiwix error we are handling them on our end.

Otherwise open a bug in openzim/libkiwix.

Sorry for not opening the issue on the libkiwix repo I only ask @mgautierfr for the might possible solution for open Xapain without filepath in #3628, but now I opened a ticket in libzim for it openzim/libzim#852.

@kelson42
Copy link
Collaborator

Yes, I understand how these functions are working they both need access to the file path to properly work with the Xapian and in the PS version we have this limitation that is why we are encountering this type of problem. But now we are not waiting for libkiwix error we are handling them on our end.

Don't open a file via fd if this will generate an exception, this is what your fix should do. Not catching an exception.

@MohitMaliFtechiz
Copy link
Collaborator Author

Don't open a file via fd if this will generate an exception, this is what your fix should do. Not catching an exception.

@kelson42 Let me explain what is going on in PS version.

In the PS version there is no way to open the ZIM file when a user tries to open this by just clicking on it, since we do not have permission to access that ZIM file via its path, whether we can open it via filePath or fileDescriptor both will throw permission denied exception. However, in the non PS version, there is no error while reading this by filePath or fileDescriptor we have the necessary permission for both.

Are you pointing to disabling this feature in the Play Store variant?

For this reason, I thought you asking for disabling the feature. But you were not pointing to this, so for this, we have to catch the exception as we can not open the ZIM file via both filePath and fileDescriptor in the PS variant, we are checking this before passing it to the libkiwix so that libkiwix will not throw any error.

let me know if anything is still unclear about this fix.

@gouri-panda
Copy link
Collaborator

@kelson42 Are you ok with the current solution? Then I can move on with the review.

@kelson42
Copy link
Collaborator

kelson42 commented Jan 30, 2024

No! Confusing exception mgmt with error mgmt is NOK. code should be adapted to avoid triggering this exception. Its trivial to do one way for PS version and another way for non PS version if this is necessary for the user get the best UX.

@MohitMaliFtechiz
Copy link
Collaborator Author

Don't open a file via fd if this will generate an exception, this is what your fix should do. Not catching an exception. code should be adapted to avoid triggering this exception.

@kelson42, @gouri-panda I have made the changes in the code according to your request.

@gouri-panda
Copy link
Collaborator

@MohitMaliDeveloper Thanks! sorry for being late in this thread! I'll look into that.

…SuggestionSearcher.

* The crashes occurred in the Play Store version due to insufficient permissions for opening a file via `fileDescriptor`. To address this issue, we have modified the implementation to use the `file` instead of `fileDescriptor`. This adjustment ensures smooth operation in the non-Play Store version where we have permission to open a file via its path. In the Play Store version, it will display a proper error message to the user, preventing errors thrown by libkiwix.
Copy link
Collaborator

@gouri-panda gouri-panda left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kelson42 LGTM!

Comment on lines +310 to +314
private fun getZimFileFromUri(
uri: Uri
): File? {
val filePath = FileUtils.getLocalFilePathByUri(
requireActivity().applicationContext, uri
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MohitMaliDeveloper we should add tests for this. Maybe in a new PR. This PR is too old now.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay sure.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MohitMaliDeveloper In such case, please update immediatly a new issue, I think this has not been done.

@kelson42 kelson42 merged commit f65787b into main Feb 14, 2024
9 of 10 checks passed
@kelson42 kelson42 deleted the Fix#3643 branch February 14, 2024 06:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Version 3.9.1 sometimes crashing while setting the SuggestionSearcher.
4 participants