mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-01-19 22:23:51 +00:00
Fail early if trying to read a string larger than the nif file size.
This is much better than failing after a few minutes with an out of memory error.
This commit is contained in:
parent
912dcdc418
commit
018f4e6895
1 changed files with 5 additions and 0 deletions
|
@ -83,6 +83,11 @@ Transformation NIFStream::getTrafo()
|
||||||
|
|
||||||
std::string NIFStream::getString(size_t length)
|
std::string NIFStream::getString(size_t length)
|
||||||
{
|
{
|
||||||
|
//Make sure we're not reading in too large of a string
|
||||||
|
unsigned int fileSize = inp->size();
|
||||||
|
if(fileSize != 0 && fileSize < length)
|
||||||
|
file->fail("Attempted to read a string with " + Ogre::StringConverter::toString(length) + "characters , but file is only "+Ogre::StringConverter::toString(fileSize)+ "bytes!");
|
||||||
|
|
||||||
std::vector<char> str (length+1, 0);
|
std::vector<char> str (length+1, 0);
|
||||||
|
|
||||||
if(inp->read(&str[0], length) != length)
|
if(inp->read(&str[0], length) != length)
|
||||||
|
|
Loading…
Reference in a new issue