[Android] Fix possible NullDereference

Jean-Baptiste Kempf git at videolan.org
Thu Jul 17 08:19:35 CEST 2014


vlc-ports/android | branch: master | Jean-Baptiste Kempf <jb at videolan.org> | Thu Jul 17 08:12:26 2014 +0200| [5fc4221900f0e41e847a717a06fe1940863cbc50] | committer: Jean-Baptiste Kempf

Fix possible NullDereference

Uri.Decode can return null if input is Null.
ThereforeURItoFile can return Null if input is Null, and so can URIToFileName.
Media.mLocation could be null (that would be stupid though), and
therefore Media.getFileName could be null and getTitle would crash.

Media.getTitle() will now return an empty string and the other cases
will be checked.

> http://git.videolan.org/gitweb.cgi/vlc-ports/android.git/?a=commit;h=5fc4221900f0e41e847a717a06fe1940863cbc50
---

 vlc-android/src/org/videolan/libvlc/LibVlcUtil.java |    2 ++
 vlc-android/src/org/videolan/libvlc/Media.java      |    9 ++++++---
 2 files changed, 8 insertions(+), 3 deletions(-)

diff --git a/vlc-android/src/org/videolan/libvlc/LibVlcUtil.java b/vlc-android/src/org/videolan/libvlc/LibVlcUtil.java
index cbc45f4..bf1024e 100644
--- a/vlc-android/src/org/videolan/libvlc/LibVlcUtil.java
+++ b/vlc-android/src/org/videolan/libvlc/LibVlcUtil.java
@@ -85,10 +85,12 @@ public class LibVlcUtil {
     }
 
     public static File URItoFile(String URI) {
+        if(URI == null) return null;
         return new File(Uri.decode(URI).replace("file://",""));
     }
 
     public static String URItoFileName(String URI) {
+        if(URI == null) return null;
         return URItoFile(URI).getName();
     }
 
diff --git a/vlc-android/src/org/videolan/libvlc/Media.java b/vlc-android/src/org/videolan/libvlc/Media.java
index cba183f..62b6fc1 100644
--- a/vlc-android/src/org/videolan/libvlc/Media.java
+++ b/vlc-android/src/org/videolan/libvlc/Media.java
@@ -356,10 +356,13 @@ public class Media implements Comparable<Media> {
         if (mTitle != null && mType != TYPE_VIDEO)
             return mTitle;
         else {
-            int end = getFileName().lastIndexOf(".");
+            String fileName = getFileName();
+            if (fileName == null)
+                return new String();
+            int end = fileName.lastIndexOf(".");
             if (end <= 0)
-                return getFileName();
-            return getFileName().substring(0, end);
+                return fileName;
+            return fileName.substring(0, end);
         }
     }
 



More information about the Android mailing list