From 21fbaf8f11faa1ccf00f60abc78d055a07a86281 Mon Sep 17 00:00:00 2001 From: Nehon Date: Sat, 9 Sep 2017 18:34:03 +0200 Subject: [PATCH] glTF: prevent direct loading of .bin files. --- .../java/com/jme3/scene/plugins/gltf/BinDataKey.java | 12 ++++++++++++ .../java/com/jme3/scene/plugins/gltf/BinLoader.java | 8 ++++++-- .../java/com/jme3/scene/plugins/gltf/GltfLoader.java | 3 ++- 3 files changed, 20 insertions(+), 3 deletions(-) create mode 100644 jme3-plugins/src/gltf/java/com/jme3/scene/plugins/gltf/BinDataKey.java diff --git a/jme3-plugins/src/gltf/java/com/jme3/scene/plugins/gltf/BinDataKey.java b/jme3-plugins/src/gltf/java/com/jme3/scene/plugins/gltf/BinDataKey.java new file mode 100644 index 000000000..c84678751 --- /dev/null +++ b/jme3-plugins/src/gltf/java/com/jme3/scene/plugins/gltf/BinDataKey.java @@ -0,0 +1,12 @@ +package com.jme3.scene.plugins.gltf; + +import com.jme3.asset.AssetKey; + +/** + * Created by Nehon on 09/09/2017. + */ +class BinDataKey extends AssetKey { + public BinDataKey(String name) { + super(name); + } +} diff --git a/jme3-plugins/src/gltf/java/com/jme3/scene/plugins/gltf/BinLoader.java b/jme3-plugins/src/gltf/java/com/jme3/scene/plugins/gltf/BinLoader.java index b4b7fbf4d..17826d59c 100644 --- a/jme3-plugins/src/gltf/java/com/jme3/scene/plugins/gltf/BinLoader.java +++ b/jme3-plugins/src/gltf/java/com/jme3/scene/plugins/gltf/BinLoader.java @@ -1,7 +1,6 @@ package com.jme3.scene.plugins.gltf; -import com.jme3.asset.AssetInfo; -import com.jme3.asset.AssetLoader; +import com.jme3.asset.*; import java.io.IOException; @@ -11,6 +10,11 @@ import java.io.IOException; public class BinLoader implements AssetLoader { @Override public Object load(AssetInfo assetInfo) throws IOException { + + if (!(assetInfo.getKey() instanceof BinDataKey)) { + throw new AssetLoadException(".bin files cannot be loaded directly, load the associated .gltf file"); + } + return assetInfo.openStream(); } } diff --git a/jme3-plugins/src/gltf/java/com/jme3/scene/plugins/gltf/GltfLoader.java b/jme3-plugins/src/gltf/java/com/jme3/scene/plugins/gltf/GltfLoader.java index 25ce90977..6536bdf2f 100644 --- a/jme3-plugins/src/gltf/java/com/jme3/scene/plugins/gltf/GltfLoader.java +++ b/jme3-plugins/src/gltf/java/com/jme3/scene/plugins/gltf/GltfLoader.java @@ -499,7 +499,8 @@ public class GltfLoader implements AssetLoader { throw new AssetLoadException("Cannot load " + uri + ", a .bin extension is required."); } - InputStream input = (InputStream) info.getManager().loadAsset(info.getKey().getFolder() + uri); + BinDataKey key = new BinDataKey(info.getKey().getFolder() + uri); + InputStream input = (InputStream) info.getManager().loadAsset(key); data = new byte[bufferLength]; input.read(data); }