glb の parse を厳格に

This commit is contained in:
ousttrue 2022-01-18 13:20:21 +09:00
parent 95fb2eba1d
commit 79cad1342d

View File

@ -1,4 +1,6 @@
using System;
using System.IO;
using System.Linq;
using NUnit.Framework;
namespace UniGLTF
@ -37,5 +39,40 @@ namespace UniGLTF
// NOTE: 大文字小文字が違うだけの名前は、同一としてみなされ、Suffix が付く。
Assert.AreEqual("foobar__UNIGLTF__DUPLICATED__2", parsed.GLTF.textures[1].name);
}
/// <summary>
/// ヘッダが正しいが、後ろが切れている場合に throw する
/// </summary>
[Test]
public void GlbLengthTest()
{
var env = System.Environment.GetEnvironmentVariable("GLTF_SAMPLE_MODELS");
if (string.IsNullOrEmpty(env))
{
return;
}
var root = new DirectoryInfo($"{env}/2.0");
if (!root.Exists)
{
return;
}
var path = Path.Combine(root.ToString(), "DamagedHelmet\\glTF-Binary\\DamagedHelmet.glb");
Assert.True(File.Exists(path));
var bytes = File.ReadAllBytes(path);
var data = new GlbBinaryParser(bytes, Path.GetFileNameWithoutExtension(path)).Parse();
// 2個目のチャンクを削る
var mod = bytes.Take(12 + 8 + data.Chunks[0].Bytes.Count).ToArray();
// 再パース
Assert.Throws<IOException>(() =>
{
var data2 = new GlbBinaryParser(mod, Path.GetFileNameWithoutExtension(path)).Parse();
});
var a = 0;
}
}
}
}