[libbluray-devel] [Git][videolan/libbluray][master] FileInputStream: resolve resource urls obtained from URL.getPath()

Petri Hintukainen gitlab at videolan.org
Fri Apr 19 22:03:42 CEST 2019



Petri Hintukainen pushed to branch master at VideoLAN / libbluray


Commits:
38bbd8e8 by hpi1 at 2019-04-19T19:58:02Z
FileInputStream: resolve resource urls obtained from URL.getPath()

Ex. Aeon Flux, Petit Prince open files from JAR with code like:
new FileInputStream(ClassLoader.getResource("menu.bin").getPath());
-> "file:/tmp/libbluray-bdj-cache/100d22e59d6d4/VFSCache/BDMV/JAR/00001.jar!/menu.bin"

Fixes #5

- - - - -


1 changed file:

- src/libbluray/bdj/java-j2se/java/io/FileInputStream.java


Changes:

=====================================
src/libbluray/bdj/java-j2se/java/io/FileInputStream.java
=====================================
@@ -23,6 +23,7 @@ import java.lang.reflect.InvocationTargetException;
 import org.videolan.BDJLoader;
 import org.videolan.BDJXletContext;
 import org.videolan.Logger;
+import org.videolan.MountManager;
 
 public class FileInputStream extends InputStream
 {
@@ -38,6 +39,27 @@ public class FileInputStream extends InputStream
     public FileInputStream(File file) throws FileNotFoundException {
         String name = file != null ? file.getPath() : null;
 
+        /* Resolve resource urls obtained from URL.getPath(). */
+        /* Ex. Aeon Flux, Petit Prince: file:/tmp/libbluray-bdj-cache/100d22e59d6d4/VFSCache/BDMV/JAR/00001.jar!/menu.bin */
+        if (name != null && name.startsWith("file:")) {
+            int idx;
+            if ((idx = name.indexOf(".jar!/")) > 0 || (idx = name.indexOf(".jar!\\")) > 0) {
+                try {
+                    String mountPoint = MountManager.getMount(Integer.parseInt(name.substring(idx - 5, idx)));
+                    if (mountPoint != null) {
+                        name = mountPoint + name.substring(idx + 5);
+                        getLogger().info("Fixing invalid resource url " + file + " --> " + name);
+                        file = new File(name);
+                    }
+                } catch (Exception e) {
+                    getLogger().error("" + e);
+                }
+            }
+        }
+        if (name.startsWith("file:")) {
+            System.err.println("ERROR: URL in FileInputStream: " + name);
+        }
+
         SecurityManager security = System.getSecurityManager();
         if (security != null) {
             security.checkRead(name);



View it on GitLab: https://code.videolan.org/videolan/libbluray/commit/38bbd8e8b146b602adf92f74a7cf58a8cb000144

-- 
View it on GitLab: https://code.videolan.org/videolan/libbluray/commit/38bbd8e8b146b602adf92f74a7cf58a8cb000144
You're receiving this email because of your account on code.videolan.org.



More information about the libbluray-devel mailing list