From 018f4e6895177c8290d52ca3b49c0319a4ecdfd2 Mon Sep 17 00:00:00 2001 From: Arthur Moore Date: Sun, 30 Nov 2014 18:59:05 -0500 Subject: [PATCH] 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. --- components/nif/nifstream.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/components/nif/nifstream.cpp b/components/nif/nifstream.cpp index a6fd5ef5a..1b5f715bc 100644 --- a/components/nif/nifstream.cpp +++ b/components/nif/nifstream.cpp @@ -83,6 +83,11 @@ Transformation NIFStream::getTrafo() 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 str (length+1, 0); if(inp->read(&str[0], length) != length)