f3d
f3d copied to clipboard
MDL Parser overhaul for better safety
Describe your changes
- 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
- see
peek_from_vector&read_from_vector - note : there were some areas where this code didn't work properly and some manual checking code was added
- magic number checking
- 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 updateddocker_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?
I'll go through tomorrow and try add some proper comments
Ah sorry, you can ignore that request. I was just just trying to access the requested changes
\ci fast
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)) >