f3d icon indicating copy to clipboard operation
f3d copied to clipboard

MDL Parser overhaul for better safety

Open iommu opened this issue 3 weeks ago • 4 comments

Describe your changes

  1. replaces majority of the raw std::vector<>.data() accessors with calls to a safe(er) helper function which ensures that the data trying to be accessed won't run over the size of the vector
  1. magic number checking
  2. Small datatype changes
  • unsigned char -> uint8_t
  • int indexing type -> size_t

Issue ticket number and link if any

#2704

Checklist for finalizing the PR

  • [X] I have performed a self-review of my code
  • [ ] I have added tests for new features and bugfixes
  • [ ] I have added documentation for new features
  • [ ] If it is a modifying the libf3d API, I have updated bindings
  • [ ] If it is a modifying the .github/workflows/versions.json, I have updated docker_timestamp

Continuous integration

Please write a comment to run CI, eg: \ci fast. See here for more info.

Notes

Should I add a specifically designed test file to ensure the parsers correct operation?

iommu avatar Dec 09 '25 17:12 iommu

I'll go through tomorrow and try add some proper comments

iommu avatar Dec 09 '25 17:12 iommu

Ah sorry, you can ignore that request. I was just just trying to access the requested changes

iommu avatar Dec 09 '25 23:12 iommu

\ci fast

mwestphal avatar Dec 10 '25 07:12 mwestphal

Style Checks CI failed:

diff --git a/plugins/native/module/Testing/TestF3DQuakeMDLParser.cxx b/plugins/native/module/Testing/TestF3DQuakeMDLParser.cxx
index 02e5b38..725599f 100644
--- a/plugins/native/module/Testing/TestF3DQuakeMDLParser.cxx
+++ b/plugins/native/module/Testing/TestF3DQuakeMDLParser.cxx
@@ -1,4 +1,4 @@
-#include <regex> // slow, but thats ok for a test
+#include <regex> // slow, but that's ok for a test
 #include <vtkCallbackCommand.h>
 #include <vtkCommand.h>
 #include <vtkDataSet.h>
@@ -79,7 +79,7 @@ int TestF3DQuakeMDLParser(int vtkNotUsed(argc), char* argv[])
     // Test "0bytes"
     // 0 byte .mdl file
 
-    // Error data we expect to recive from calling importer on this "file"
+    // Error data we expect to receive from calling importer on this "file"
     ExpectedError expected{ .fileName = "vtkF3DQuakeMDLImporter.cxx",
       .lineNumber = "573",
       .errorString = "Unable to read header, aborting." };
diff --git a/plugins/native/module/vtkF3DQuakeMDLImporter.cxx b/plugins/native/module/vtkF3DQuakeMDLImporter.cxx
index 1f4882c..b09571f 100644
--- a/plugins/native/module/vtkF3DQuakeMDLImporter.cxx
+++ b/plugins/native/module/vtkF3DQuakeMDLImporter.cxx
@@ -371,7 +371,7 @@ struct vtkF3DQuakeMDLImporter::vtkInternals
 
           frameOffsets.emplace_back(std::vector<int>());
 
-          // check that we wont run off the buffer during loop
+          // check that we won't run off the buffer during loop
           if (offset +
               (*framePtr[i].nb *
                 (mdl_simpleframe_t_fixed_size + sizeof(mdl_vertex_t) * header->numVertices)) >

github-actions[bot] avatar Dec 10 '25 07:12 github-actions[bot]