[vtk-developers] reproducible vtkXMLImageDataReader + vtkImageCast segfault

Charl P. Botha c.p.botha at ewi.tudelft.nl
Tue Mar 16 08:59:01 EST 2004


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,
Charl

-- 
charl p. botha http://cpbotha.net/ http://visualisation.tudelft.nl/

-------------- next part --------------
A non-text attachment was scrubbed...
Name: xmlreader.extentfix.diff
Type: text/x-patch
Size: 1516 bytes
Desc: not available
URL: <http://public.kitware.com/pipermail/vtk-developers/attachments/20040316/c233fd8a/attachment-0001.bin>


More information about the vtk-developers mailing list