# Crash in vtkImageExport

**URL:** https://discourse.vtk.org/t/crash-in-vtkimageexport/16415
**Category:** Development
**Created:** [May 12, 2026, 10:05am UTC](https://discourse.vtk.org/t/crash-in-vtkimageexport/16415 "2026-05-12T10:05:12Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![nbeck](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/n/97f17d/32.png) [@nbeck](https://discourse.vtk.org/u/nbeck)
#### Post date: [May 12, 2026, 10:05am UTC](https://discourse.vtk.org/t/crash-in-vtkimageexport/16415/1 "2026-05-12T10:05:12Z")

</div>

Hello,

we’ve encountered spurious crashes with our application when processing large data sets. Some debugging revealed that we had invalid memory access in `vtkImageExport::export()`. Further investigation showed that the calculated memory size was off due to an integer overflow.

```auto
vtkIdType vtkImageExport::GetDataMemorySize()
{
  vtkImageData* input = this->GetInput();
  if (input == nullptr)
  {
    return 0;
  }

  this->GetInputAlgorithm()->UpdateInformation();
  vtkInformation* inInfo = this->GetInputInformation();
  int* extent = inInfo->Get(vtkStreamingDemandDrivenPipeline::WHOLE_EXTENT());
  int size = input->GetScalarSize();
  size *= input->GetNumberOfScalarComponents();
  size *= (extent[1] - extent[0] + 1);
  size *= (extent[3] - extent[2] + 1);
  size *= (extent[5] - extent[4] + 1);

  return size;
}

```

While the calculated size is returned as a `vtkIdType`, it is calculated as an `int`. For large data sets with `double` scalars this can easily overflow.

---

<div class="post-metadata">

### Author: ![nbeck](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/n/97f17d/32.png) [@nbeck](https://discourse.vtk.org/u/nbeck)
#### Post date: [May 12, 2026, 1:09pm UTC](https://discourse.vtk.org/t/crash-in-vtkimageexport/16415/2 "2026-05-12T13:09:22Z")

</div>

[https://gitlab.kitware.com/vtk/vtk/-/work\_items/20044](https://gitlab.kitware.com/vtk/vtk/-/work_items/20044)

---

<div class="post-metadata">

### Author: ![Paulo\_Carvalho](https://discourse.vtk.org/user_avatar/discourse.vtk.org/paulo_carvalho/32/370_2.png) [@Paulo\_Carvalho](https://discourse.vtk.org/u/Paulo_Carvalho)
#### Post date: [May 12, 2026, 6:20pm UTC](https://discourse.vtk.org/t/crash-in-vtkimageexport/16415/3 "2026-05-12T18:20:52Z")

</div>

Hello,

It is unsafe to assume `int` is 64-bit even on 64-bit systems. `sizeof()` anything other than `char` is compiler-specific. I’d use the safer `long` there.

best,

PC
