MantisBT - VTK
View Issue Details
0006771VTK(No Category)public2008-04-08 09:302016-08-12 09:54
Levap 
Kitware Robot 
normalcrashalways
closedmoved 
 
 
0006771: Bug in vtkImageReader
The following code snippet leads to crash (null pointer access) on a Windows XP 32bit SP2, with 2 GB RAM.

Code snippet:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
vtkImageData* img = vtkImageDate::New();

vtkImageReader* ir = vtkImageReader::New();
ir->SetFileName(“d:\\myvolume.raw”);
ir->SetFileDimensionality(3);
ir->SetDataByteOrderToLittleEndian();
ir->SetDataScalarType(VTK_FLOAT);
ir->SetDataExtent(0, 580, 0, 580, 0, 500);

ir->SetDataOrigin(0, 0, 0);
ir->SetDataSpacing(1, 1, 1);
ir->SetHeaderSize(0); // no header
ir->SetNumberOfScalarComponents(1);
ir->SwapBytesOff();
ir->SetFileLowerLeft(1);
ir->SetOutput(img);

ir->Update();

ir->Delete();
img->Delete();
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Explanation and approach to a problem:

I’m trying to load a large volume (> 640 MB), but operating system fails to allocate enough memory in the function vtkDataArrayTemplate<T>::Allocate(vtkIdType sz, vtkIdType) (file: vtkDataArrayTemplate.txx), so it leads to a following error massege:

ERROR: In d:\work\libs\vtk\5_1_0\source\common\vtkDataArrayTemplate.txx, line 133
vtkFloatArray (02736950): Unable to allocate 168200000 elements of size 4 bytes.

This behavior is OK! The problem is the next step: despite of the false allocation the vtkImageReader tries to load the volume and make an access to null pointer -> this leads to a crash.
Let us take a close look at the function vtkImageReader::ExecuteData(vtkDataObject *output) in the file vtkImageReader.cxx. The error message is produced during the call in the first line of the function:

vtkImageData *data = this->AllocateOutputData(output);

After this line I would place a check block for a successful memory allocation, something like this:

if (!data->GetScalarPointer())
{
  return;
}
No tags attached.
Issue History
2008-04-08 09:30LevapNew Issue
2011-06-16 13:11Zack GalbreathCategory => (No Category)
2016-08-12 09:54Kitware RobotNote Added: 0036966
2016-08-12 09:54Kitware RobotStatusexpired => closed
2016-08-12 09:54Kitware RobotResolutionopen => moved
2016-08-12 09:54Kitware RobotAssigned To => Kitware Robot

Notes
(0036966)
Kitware Robot   
2016-08-12 09:54   
Resolving issue as `moved`.

This issue tracker is no longer used. Further discussion of this issue may take place in the current VTK Issues page linked in the banner at the top of this page.