From 2730837b99e8c24110cc783e63ccb9b1144a98da Mon Sep 17 00:00:00 2001 From: Louis Gombert Date: Wed, 19 Jul 2023 12:16:34 +0200 Subject: [PATCH] VTK FiberSurface : detect ill-formed range polygons to avoid out-of-bounds array access --- core/vtk/ttkFiberSurface/ttkFiberSurface.cpp | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/core/vtk/ttkFiberSurface/ttkFiberSurface.cpp b/core/vtk/ttkFiberSurface/ttkFiberSurface.cpp index 69af9b455a..2932fde216 100644 --- a/core/vtk/ttkFiberSurface/ttkFiberSurface.cpp +++ b/core/vtk/ttkFiberSurface/ttkFiberSurface.cpp @@ -114,15 +114,21 @@ int ttkFiberSurface::RequestData(vtkInformation *ttkNotUsed(request), inputPolygon_.clear(); + SimplexId cellNumber = polygon->GetNumberOfCells(); + vtkCellArray *connectivity = polygon->GetCells(); + + if(connectivity->GetData()->GetNumberOfTuples() < 3 * cellNumber) { + this->printErr("Error: ill-defined range polygon."); + return 0; + } + #if !defined(_WIN32) || defined(_WIN32) && defined(VTK_USE_64BIT_IDS) - const long long int *cellArray - = polygon->GetCells()->GetData()->GetPointer(0); + const long long int *cellArray = connectivity->GetData()->GetPointer(0); #else - int *pt = polygon->GetCells()->GetPointer(); + int *pt = connectivity->GetPointer(); long long extra_pt = *pt; const long long int *cellArray = &extra_pt; #endif - SimplexId cellNumber = polygon->GetNumberOfCells(); SimplexId vertexId0, vertexId1; std::pair, std::pair> rangeEdge;