Crash in Superimpose with PHR mode
Description
The application Superimpose
crashed with a segmentation fault during resampling:
Program received signal SIGSEGV, Segmentation fault.
0x00002aaaedf394ee in itk::NearestNeighborInterpolateImageFunction<otb::VectorImage<float, 2u>, double>::EvaluateAtContinuousIndex(itk::ContinuousIndex<double, 2u> const&) const () from /usr/local/otb/lib/otb/applications/otbapp_Superimpose.so
(gdb) bt
#0 0x00002aaaedf394ee in itk::NearestNeighborInterpolateImageFunction<otb::VectorImage<float, 2u>, double>::EvaluateAtContinuousIndex(itk::ContinuousIndex<double, 2u> const&) const () from /usr/local/otb/lib/otb/applications/otbapp_Superimpose.so
#1 0x00002aaaedf3aa52 in otb::GridResampleImageFilter<otb::VectorImage<float, 2u>, otb::VectorImage<float, 2u>, double>::ThreadedGenerateData(itk::ImageRegion<2u> const&, unsigned int) () from /usr/local/otb/lib/otb/applications/otbapp_Superimpose.so
#2 0x00002aaaedf2205b in itk::ImageSource<otb::VectorImage<float, 2u> >::ThreaderCallback(void*) () from /usr/local/otb/lib/otb/applications/otbapp_Superimpose.so
#3 0x00002aaad5781ee8 in itk::MultiThreader::SingleMethodExecute() () from /usr/local/otb/lib/libITKCommon-4.13.so.1
#4 0x00002aaaedf1cad0 in itk::ImageSource<otb::VectorImage<float, 2u> >::GenerateData() () from /usr/local/otb/lib/otb/applications/otbapp_Superimpose.so
#5 0x00002aaad577ce45 in itk::ProcessObject::UpdateOutputData(itk::DataObject*) () from /usr/local/otb/lib/libITKCommon-4.13.so.1
#6 0x00002aaad577ccaf in itk::ProcessObject::UpdateOutputData(itk::DataObject*) () from /usr/local/otb/lib/libITKCommon-4.13.so.1
#7 0x00002aaad577ce18 in itk::ProcessObject::UpdateOutputData(itk::DataObject*) () from /usr/local/otb/lib/libITKCommon-4.13.so.1
#8 0x00002aaad577ce18 in itk::ProcessObject::UpdateOutputData(itk::DataObject*) () from /usr/local/otb/lib/libITKCommon-4.13.so.1
#9 0x00002aaad1bab503 in otb::ImageFileWriter<otb::VectorImage<unsigned char, 2u> >::Update() () from /usr/local/otb/lib/libOTBImageIO-7.0.so.1
#10 0x00002aaad129cec4 in otb::Wrapper::OutputImageParameter::Write() () from /usr/local/otb/lib/libOTBApplicationEngine-7.0.so.1
#11 0x00002aaad144aa25 in otb::Wrapper::Application::WriteOutput() () from /usr/local/otb/lib/libOTBApplicationEngine-7.0.so.1
#12 0x00002aaad144ff4c in otb::Wrapper::Application::ExecuteAndWriteOutput() () from /usr/local/otb/lib/libOTBApplicationEngine-7.0.so.1
#13 0x00002aaad0a4fe49 in _wrap_Application_ExecuteAndWriteOutput () from /usr/local/otb/lib/python/_otbApplication.so
After investigation I found that the interpolated index was out of image bounds.
Steps to reproduce
Quite difficult to reproduce, I had this crash when running a larger processing chain calling OTB applications from Python. I tried to call the OTB application out of the chain but couldn't reproduce the bug. Basically, I ran Superimpose with the following parameters:
-
inr
: a PHR Pan image -
inm
: the corresponding PHR XS image -
interpolator
: Nearest neighbor (this setting is important to reproduce the bug)
The application uses the PHR mode and resample the XS image with a otb::GridResampleImageFilter
.
This filter doesn't check explicitely that input indexes are in the input buffered region. It uses a m_ReachableOutputRegion
to crop the output region processed. The problem appears because an output pixel is right on the border of the input image extent, and since I use a nearest neighbor interpolator, this one converts the continuous index to an out-of-bound index. To illustrate on a simple case:
- Input image
- origin [0.5, 0.5]
- spacing [1, 1]
- size [10, 10]
- so the physical extent is [0., 0.] to [10.0, 10.0]
- If I have an output pixel whose center is at physical position [5.5, 10.0]
- you can say that it is inside the input physical extent
- but its continuous index in input image is [5.0, 9.5]
- so its index is then [5, 10] -> OUT-OF-BOUND
Configuration information
OS: centOS 7 OTB: rev. 6aca6c3e Standalone package
Proposed patch
I solved this problem by adding an epsilon margin to compute the m_ReachableOutputRegion
.
You can adapt this patch, it also answers partially the comment about interpolation radius in otbGridResampleImageFilter.hxx
.superimpose_segfault.patch