diff --git a/Accelerators/Vtkm/Core/vtkmlib/DataArrayConverters.cxx b/Accelerators/Vtkm/Core/vtkmlib/DataArrayConverters.cxx index 35cfd734ac30b7f7ada54418e2ad2e4e0460deec..e94c6d4b885371afc4fc41691ca8deb120345b04 100644 --- a/Accelerators/Vtkm/Core/vtkmlib/DataArrayConverters.cxx +++ b/Accelerators/Vtkm/Core/vtkmlib/DataArrayConverters.cxx @@ -14,6 +14,9 @@ #include "vtkDataArray.h" #include "vtkPoints.h" +#include <cstdint> +#include <limits> + namespace fromvtkm { VTK_ABI_NAMESPACE_BEGIN @@ -114,6 +117,17 @@ public: } else { + if (static_cast<std::size_t>(size) >= + static_cast<std::size_t>(std::numeric_limits<std::ptrdiff_t>::max()) / sizeof(ValueType)) + { + this->Data = nullptr; + array->Delete(); + std::ostringstream err; + err << "Allocation request too big: " << size << " elements of " << sizeof(ValueType) + << " bytes"; + throw vtkm::cont::ErrorBadAllocation(err.str()); + } + // deep copy the memory to VTK as the memory coming from // a source that VTK can't represent ValueType* dataBuffer = new ValueType[size];