[vtk-developers] reproducible vtkXMLImageDataReader + vtkImageCast segfault

Brad King brad.king at kitware.com
Tue Mar 16 14:00:39 EST 2004


Charl P. Botha wrote:

> On Tue, 2004-03-16 at 12:31, Charl P. Botha wrote:
> 
>>The vtkXMLImageReader, when running into an error during reading, sets
>>Extent to empty, but UpdateExtent and WholeExtent are left as they were
>>before.  vtkImageCast (and undoubtedly other filters) are happy as long
>>as the input is set and UpdateExtent is not empty.
>>
>>In this case, it derefs a pointer which is not valid anymore and
>>segfaults badly.
> 
> 
> I've remedied this problem with the attached patch (already applied). 
> There were two problems: 
> 
> 1. vtkXMLReader wasn't calling SetupEmptyOutput() at file opening
> error.  This is _crucially important_, but doesn't usually get caught as
> VTK filters don't usually get tested in a disconnection/reconnection
> scenario.
> 
> 2. The definition of SetupEmptyOutput in vtkXMLStructuredDataReader was
> only setting UpdateExtent to the empty volume.  It should also set
> WholeExtent.
> 
> Lessons:
> * VTK filters aren't always robust to disconnections and reconnections.
> * Many VTK filters are especially vulnerable to changing input, e.g.
> file reader with valid output as input to a subsequent filter, change
> filename to non-existent, file reader output is invalid (weird extents,
> possibly NULL GetScalarPointer, etc. result in the subsequent filter)
> 
> Another 2c (if you've heard this before, stop reading :) : I believe
> that exception-based error handling would solve many of these problems. 
> As I've said before: VTK pipeline execution continues even after an
> error.  With exception-based error handling, execution would stop at the
> error, thus preventing any nasties.  This means that developers don't
> have to spend time coding for every possible weird permutation of data
> and metadata that happens because of errors earlier in the pipeline.

Thanks for tracking this down.  Your fix looks good.  The new pipeline
using vtkAlgorithm/vtkExecutive superclasses will not execute a filter
until its input has been validated by its executive.  This should
resolve many of these problems.

-Brad






More information about the vtk-developers mailing list