[Android] Prevent crash on IOException

Nicolas Pomepuy git at videolan.org
Tue Sep 10 09:29:29 UTC 2024


vlc-android | branch: master | Nicolas Pomepuy <nicolas at videolabs.io> | Tue Sep 10 09:05:00 2024 +0200| [196ab52f349fda23872777fdcd97a91cc08b5296] | committer: Nicolas Pomepuy

Prevent crash on IOException

Fixes #3084

> https://code.videolan.org/videolan/vlc-android/commit/196ab52f349fda23872777fdcd97a91cc08b5296
---

 application/vlc-android/src/org/videolan/vlc/FileProvider.kt | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/application/vlc-android/src/org/videolan/vlc/FileProvider.kt b/application/vlc-android/src/org/videolan/vlc/FileProvider.kt
index ad27376c8f..e6da05b92c 100644
--- a/application/vlc-android/src/org/videolan/vlc/FileProvider.kt
+++ b/application/vlc-android/src/org/videolan/vlc/FileProvider.kt
@@ -5,11 +5,13 @@ import android.content.ContentValues
 import android.database.Cursor
 import android.net.Uri
 import android.os.ParcelFileDescriptor
+import android.util.Log
 import org.videolan.medialibrary.interfaces.Medialibrary
 import org.videolan.resources.AndroidDevices
 import org.videolan.resources.AppContextProvider
 import java.io.File
 import java.io.FileNotFoundException
+import java.io.IOException
 
 private const val TAG = "VLC/FileProvider"
 private const val THUMB_PROVIDER_AUTHORITY = "${BuildConfig.APP_ID}.thumbprovider"
@@ -58,6 +60,12 @@ fun getUpdateUri() = Uri.Builder()
         .build()!!
 
 fun isPathValid(path: String): Boolean {
-    val file = File(path)
+    val file = try {
+        File(path)
+    } catch (e: IOException) {
+        Log.e(TAG, "Failed to parse path: $path")
+        Log.e(TAG, e.message, e)
+        return false
+    }
     return AndroidDevices.mountBL.any { file.canonicalPath.startsWith(it) } && file.canRead()
 }
\ No newline at end of file



More information about the Android mailing list