Explorar o código

Merge pull request #327 from Dmitry-Me/ensureFileSizeFitsInSizeT

Ensure file contents fit into size_t range
Lee Thomason %!s(int64=10) %!d(string=hai) anos
pai
achega
89df56c046
Modificáronse 1 ficheiros con 6 adicións e 0 borrados
  1. 6 0
      tinyxml2.cpp

+ 6 - 0
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 );