mirror of
https://git.mirrors.martin98.com/https://github.com/syoyo/tinygltf.git
synced 2025-04-23 22:50:11 +08:00
Prevent a segfault when loading an empty file
If the size of the file is zero, we just signal an error and return false.
This commit is contained in:
parent
cf6e07b1ec
commit
b310b4a32e
@ -2286,6 +2286,13 @@ bool TinyGLTFLoader::LoadASCIIFromFile(Scene *scene, std::string *err,
|
||||
size_t sz = static_cast<size_t>(f.tellg());
|
||||
std::vector<char> buf(sz);
|
||||
|
||||
if (sz == 0) {
|
||||
if (err) {
|
||||
(*err) = "Empty file.";
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
f.seekg(0, f.beg);
|
||||
f.read(&buf.at(0), static_cast<std::streamsize>(sz));
|
||||
f.close();
|
||||
|
Loading…
x
Reference in New Issue
Block a user