Hi all,
I have encountered a problem with the itk::ImageFileWriter when writing mhd files.
When the absolute path exceeds 263 characters, the program crashes with a segfault in the UnRegister method of the itkSmartPointer.
The code (adapted from the ITK Example ImageFileWriter) to reproduce this error is here:
#include "itkImage.h"
#include "itkImageFileWriter.h"
#include <iostream>
#include <string>
int main( int argc, char* argv[] )
{
std::string absolutePathDoCrash = "/home/abcdef/Desktop/delete/itk/ImageFileWriter/build-verylongFOlderNamexxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx-Desktop_Qt_5_12_0_Clang_64bit-Debug/abcdefghijklmnopqrstuvwxyzABCDEFGHI.mhd";
std::string absolutePathNoCrash = "/home/abcdef/Desktop/delete/itk/ImageFileWriter/build-verylongFOlderNamexxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx-Desktop_Qt_5_12_0_Clang_64bit-Debug/abcdefghijklmnopqrstuvwxyzABCDEFGH.mhd";
std::string absolutePathNoComme = "/home/abcdef/Desktop/delete/itk/ImageFileWriter/build-verylongFOlderNamexxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx-Desktop_Qt_5_12_0_Clang_64bit-Debug/abcdefghijklmnopqrstuvwxyz.mhd";
typedef unsigned char PixelType;
const unsigned int Dimension = 2;
typedef itk::Image< PixelType, Dimension > ImageType;
ImageType::RegionType region;
ImageType::IndexType start;
start[0] = 0;
start[1] = 0;
ImageType::SizeType size;
size[0] = 200;
size[1] = 300;
region.SetSize( size );
region.SetIndex( start );
ImageType::Pointer image = ImageType::New();
image->SetRegions( region );
image->Allocate();
ImageType::IndexType ind;
ind[0] = 10;
ind[1] = 10;
typedef itk::ImageFileWriter< ImageType > WriterType;
WriterType::Pointer writer = WriterType::New();
writer->SetFileName( absolutePathDoCrash );
writer->SetInput( image );
writer->Update();
return EXIT_SUCCESS;
}
When I change the filename in the writer to the variable absolutePathNoCrash (one character shorter), the program runs without crash.
In both cases a Comment entry is added in the mhd file that contains the part of the file path from 256th character onward. No Comment entry in the mhd file, when the variable absolutePathNoComme is used as filename.
With all three path variables the mhd and raw file gets written.
No crash happens when the file extension is changed to png.
This was tested witk ITK 5.0RC2 on Ubuntu 18.04