In ticket the below ITK ticket an issue has been reported,
opened 11:10AM - 28 May 25 UTC
closed 01:57AM - 29 May 25 UTC
Hi, I’m using ITK version 5.4.3. While generating an NRRD file from a specific i… mage, my application crashes.
Here’s a snippet of my code:
```
using ReaderType = itk::ImageSeriesReader<ImageType>;
auto reader = ReaderType::New();
using ImageIOType = itk::GDCMImageIO;
auto dicomIO = ImageIOType::New();
reader->SetImageIO(dicomIO);
reader->SetFileNames(fileNames);
reader->ForceOrthogonalDirectionOff(); // properly read CTs with gantry tilt
std::string outFileName;
if (argc > 2)
{
outFileName = argv[2];
}
else
{
outFileName = dirName + std::string("/") + seriesIdentifier + ".nrrd";
}
std::cout << "Writing: " << outFileName << std::endl;
try
{
itk::WriteImage(reader->GetOutput(), outFileName); // the exception is occurring here
}
catch (const itk::ExceptionObject & ex)
{
std::cout << ex << std::endl;
continue;
}
```
I’ve attached a sample file for reference.
(https://drive.google.com/file/d/1Yn9WUksnnzT9AzrH5fkMqSToUhXyxxVw/view?usp=drive_link)
Could you help explain why this issue occurs and how to resolve it?
I have same DICOM files where Bits allocated is 12 for which an exception is supposed to be raised as mentioned in the ticket’s fix is not working instead my process crashes in both WINDOWS and LINUX.
I have attached DICOM files in below .zip file
DICOM.zip
In LINUX Update() triggers Abort it seems. Please refer below attached screen shot
Though the image is being invalid with 12 bits allocated, only exceptions has to be raised instead of abort which terminates my process.
NOTE: I have used the same code as mentioned in the ITK ticket as mentioned above. Please refer that code.
**
Can anyone help me with this?**
@dzenanz @zivy
Yes, the files are invalid (12 bits allocated, in fact 16 bits allocated).
This check in GDCM’s Unpacker12Bits
bool Unpacker12Bits::Unpack(char *out, const char *in, size_t n)
{
if( n % 3 ) return false; // 3bytes are actually 2 words
is not sufficient in this particular case
384×384×2 = 294912
294912÷3 = 98304
Actually I don’t know exactly how improve this.
Real help is fix the files, download here
1 Like
Adding
if (inOutBufferLength != len)
{
gdcmDebugMacro("inOutBufferLength = " << inOutBufferLength
<< ", inBufferLength = " << inBufferLength << ", len = " << len);
return false;
}
after line 119
size_t len = str.size() * 16 / 12;
may work
Edit: added forgotten ;
1 Like
I have added those lines in the mentioned file; now my service is not crashing and “Failed to get the buffer!” exception is caught.
Can we expect this handling to be merged in future PRs?
@mihail.isakov
@dzenanz
dzenanz
(Dženan Zukić)
October 16, 2025, 2:48pm
5
@mathieu.malaterre Is this the correct solution?
@purushothaman_u you could make a PR to GDCM .
@purushothaman_u
I’ve added support for those fake 12bits allocated image upstream. Please see commit f57e45134ce6f0092687d0c4a69b5d7bee991dc5
Thanks
1 Like