From 2a8b1f57895e6cc20d6a1abd859472239a749d8c Mon Sep 17 00:00:00 2001 From: Dmitry-Me Date: Thu, 30 Apr 2015 14:58:57 +0300 Subject: [PATCH] Ensure file contents fit into size_t range --- tinyxml2.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tinyxml2.cpp b/tinyxml2.cpp index 50bea56..03ce1b9 100755 --- a/tinyxml2.cpp +++ b/tinyxml2.cpp @@ -1846,6 +1846,12 @@ XMLError XMLDocument::LoadFile( FILE* fp ) return _errorID; } + if ( filelength >= (size_t)-1 ) { + // Cannot handle files which won't fit in buffer together with null terminator + SetError( XML_ERROR_FILE_READ_ERROR, 0, 0 ); + return _errorID; + } + const size_t size = filelength; if ( size == 0 ) { SetError( XML_ERROR_EMPTY_DOCUMENT, 0, 0 );