From b310b4a32e97bf8d7014d3b322166f6df1caa512 Mon Sep 17 00:00:00 2001 From: Luke San Antonio Date: Thu, 23 Jun 2016 14:17:37 -0400 Subject: [PATCH] Prevent a segfault when loading an empty file If the size of the file is zero, we just signal an error and return false. --- tiny_gltf_loader.h | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tiny_gltf_loader.h b/tiny_gltf_loader.h index 7067cdf..9cb3a46 100644 --- a/tiny_gltf_loader.h +++ b/tiny_gltf_loader.h @@ -2286,6 +2286,13 @@ bool TinyGLTFLoader::LoadASCIIFromFile(Scene *scene, std::string *err, size_t sz = static_cast(f.tellg()); std::vector buf(sz); + if (sz == 0) { + if (err) { + (*err) = "Empty file."; + } + return false; + } + f.seekg(0, f.beg); f.read(&buf.at(0), static_cast(sz)); f.close();