Skip to content

GitLab

  • Menu
Projects Groups Snippets
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • VTK VTK
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 741
    • Issues 741
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 197
    • Merge requests 197
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages & Registries
    • Packages & Registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • VTK
  • VTKVTK
  • Issues
  • #6771
Closed
Open
Created Apr 07, 2008 by Kitware Robot@kwrobotOwner

Bug in vtkImageReader

This issue was created automatically from an original Mantis Issue. Further discussion may take place here.


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::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; }

Assignee
Assign to
Time tracking