Browse Source

Fixes stack overwriting bug in gl::is_stl, when file have binary data (#1431)

* Fixes stack overwriting bug in gl::is_stl, when file have binary data
detected by running with ASAN in all_meshes test
Vladimir S. FONOV 5 years ago
parent
commit
c907add524
1 changed files with 3 additions and 1 deletions
  1. 3 1
      include/igl/is_stl.cpp

+ 3 - 1
include/igl/is_stl.cpp

@@ -1,4 +1,4 @@
-#include "is_stl.h"
+#include "is_stl.h" 
 #include <string>
 IGL_INLINE bool igl::is_stl(FILE * stl_file, bool & is_ascii)
 {
@@ -41,6 +41,8 @@ IGL_INLINE bool igl::is_stl(FILE * stl_file, bool & is_ascii)
     f = false;
     goto finish;
   }
+  // make sure sscanf doesn't read past the end of the header, overwriting stack
+  header[sizeof(header)-1]='\0';
 
   sscanf(header,"%s",solid);
   if(std::string("solid") == solid)