+ add security checks to SoBrep nodes

This commit is contained in:
wmayer
2015-10-07 23:08:03 +02:00
parent 5f5817b033
commit 5b08fa453b
5 changed files with 95 additions and 35 deletions

View File

@@ -50,6 +50,7 @@
# include <Inventor/elements/SoGLCacheContextElement.h>
# include <Inventor/elements/SoLineWidthElement.h>
# include <Inventor/elements/SoPointSizeElement.h>
# include <Inventor/errors/SoDebugError.h>
# include <Inventor/errors/SoReadError.h>
# include <Inventor/details/SoFaceDetail.h>
# include <Inventor/details/SoLineDetail.h>
@@ -153,7 +154,12 @@ void SoBrepEdgeSet::renderHighlight(SoGLRenderAction *action)
int num = (int)this->hl.size();
if (num > 0) {
const int32_t* id = &(this->hl[0]);
renderShape(static_cast<const SoGLCoordinateElement*>(coords), id, num);
if (!validIndexes(coords, this->hl)) {
SoDebugError::postWarning("SoBrepEdgeSet::renderHighlight", "highlightIndex out of range");
}
else {
renderShape(static_cast<const SoGLCoordinateElement*>(coords), id, num);
}
}
state->pop();
}
@@ -192,12 +198,26 @@ void SoBrepEdgeSet::renderSelection(SoGLRenderAction *action)
if (num > 0) {
cindices = &(this->sl[0]);
numcindices = (int)this->sl.size();
renderShape(static_cast<const SoGLCoordinateElement*>(coords), cindices, numcindices);
if (!validIndexes(coords, this->sl)) {
SoDebugError::postWarning("SoBrepEdgeSet::renderSelection", "selectionIndex out of range");
}
else {
renderShape(static_cast<const SoGLCoordinateElement*>(coords), cindices, numcindices);
}
}
state->pop();
}
bool SoBrepEdgeSet::validIndexes(const SoCoordinateElement* coords, const std::vector<int32_t>& pts) const
{
for (std::vector<int32_t>::const_iterator it = pts.begin(); it != pts.end(); ++it) {
if (*it >= coords->getNum()) {
return false;
}
}
return true;
}
static void createIndexArray(const int32_t* segm, int numsegm,
const int32_t* cindices, int numcindices,
std::vector<int32_t>& out)
@@ -292,8 +312,10 @@ void SoBrepEdgeSet::doAction(SoAction* action)
switch (selaction->getType()) {
case Gui::SoSelectionElementAction::Append:
{
int start = this->selectionIndex.getNum();
this->selectionIndex.set1Value(start, index);
if (this->selectionIndex.find(index) < 0) {
int start = this->selectionIndex.getNum();
this->selectionIndex.set1Value(start, index);
}
}
break;
case Gui::SoSelectionElementAction::Remove: