]> git.sur5r.net Git - fstl/blobdiff - src/loader.cpp
Added check for stl corruption
[fstl] / src / loader.cpp
index d7ce46a4a0e167ca560e18725c870e6f358f4f24..355f40c9c982ee621616a9105a6bf5fd5caf0c73 100644 (file)
@@ -4,6 +4,7 @@
 Loader::Loader(QObject* parent, const QString& filename)
     : QThread(parent), filename(filename)
 {
+    // Nothing to do here
 }
 
 void Loader::run()
@@ -16,6 +17,19 @@ void Loader::run()
             emit error_ascii_stl();
             return;
         }
+
+        // Skip the rest of the buffer
+        file.read(75);
+
+        // Assume we're on a little-endian system for simplicity
+        uint32_t tri_count;
+        file.read(reinterpret_cast<char*>(&tri_count), sizeof(tri_count));
+
+        if (file.size() != 84 + tri_count*50)
+        {
+            emit error_bad_stl();
+            return;
+        }
     }
 
     emit got_mesh(Mesh::load_stl(filename));