mirror of
https://git.mirrors.martin98.com/https://github.com/syoyo/tinygltf.git
synced 2025-07-09 05:41:52 +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());
|
size_t sz = static_cast<size_t>(f.tellg());
|
||||||
std::vector<char> buf(sz);
|
std::vector<char> buf(sz);
|
||||||
|
|
||||||
|
if (sz == 0) {
|
||||||
|
if (err) {
|
||||||
|
(*err) = "Empty file.";
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
f.seekg(0, f.beg);
|
f.seekg(0, f.beg);
|
||||||
f.read(&buf.at(0), static_cast<std::streamsize>(sz));
|
f.read(&buf.at(0), static_cast<std::streamsize>(sz));
|
||||||
f.close();
|
f.close();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user