Fix for obj-loader 65/136665/7
authorVictor Cebollada <v.cebollada@samsung.com>
Fri, 30 Jun 2017 15:13:27 +0000 (16:13 +0100)
committergreynaga <g.reynaga@samsung.com>
Tue, 4 Jul 2017 14:50:57 +0000 (15:50 +0100)
* Fixes an invalid read reported by valgrind.
* Fix an posible overflow

Change-Id: I57ccebb986d209b8d4deba4819b4b3cac8aced24
Signed-off-by: Victor Cebollada <v.cebollada@samsung.com>
dali-toolkit/internal/controls/model3d-view/obj-loader.cpp

index 6717bab..fca57b4 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2017 Samsung Electronics Co., Ltd.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -364,7 +364,7 @@ bool ObjLoader::LoadObject( char* objBuffer, std::streampos fileSize )
 
   std::string strMatActual;
 
-  std::string input = objBuffer;
+  std::string input( objBuffer, fileSize );
   std::istringstream ss(input);
   ss.imbue( std::locale( "C" ) );
 
@@ -442,7 +442,7 @@ bool ObjLoader::LoadObject( char* objBuffer, std::streampos fileSize )
       }
 
       int numIndices = 0;
-      while( isline >> vet[numIndices] && numIndices < MAX_POINT_INDICES )
+      while( ( numIndices < MAX_POINT_INDICES ) && ( isline >> vet[numIndices] ) )
       {
         numIndices++;
       }
@@ -566,7 +566,7 @@ void ObjLoader::LoadMaterial( char* objBuffer, std::streampos fileSize, std::str
 
   std::string info;
 
-  std::string input = objBuffer;
+  std::string input( objBuffer, fileSize );
   std::istringstream ss(input);
   ss.imbue(std::locale("C"));