# The application crashes while generating the NRRD file

**URL:** https://discourse.itk.org/t/the-application-crashes-while-generating-the-nrrd-file/7646
**Category:** Beginner Questions
**Tags:** itk
**Created:** [October 13, 2025, 6:26am UTC](https://discourse.itk.org/t/the-application-crashes-while-generating-the-nrrd-file/7646 "2025-10-13T06:26:07Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![purushothaman\_u](https://discourse.itk.org/user_avatar/discourse.itk.org/purushothaman_u/32/4593_2.png) [@purushothaman\_u](https://discourse.itk.org/u/purushothaman_u)
#### Post date: [October 13, 2025, 6:26am UTC](https://discourse.itk.org/t/the-application-crashes-while-generating-the-nrrd-file/7646/1 "2025-10-13T06:26:07Z")

</div>

In ticket the below ITK ticket an issue has been reported,

> <https://github.com/InsightSoftwareConsortium/ITK/issues/5364>
>
> 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](https://github.com/user-attachments/files/22767588/DICOM.zip)  
In LINUX Update() triggers Abort it seems. Please refer below attached screen shot

 ![image](https://discourse.itk.org/uploads/default/original/2X/9/9d978d11b9748ace09825c02da7b371c6037a0df.jpeg)

**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

---

<div class="post-metadata">

### Author: ![mihail.isakov](https://discourse.itk.org/letter_avatar_proxy/v4/letter/m/c4cdca/32.png) [@mihail.isakov](https://discourse.itk.org/u/mihail.isakov)
#### Post date: [October 13, 2025, 10:40am UTC](https://discourse.itk.org/t/the-application-crashes-while-generating-the-nrrd-file/7646/2 "2025-10-13T10:40:58Z")

</div>

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](https://drive.google.com/file/d/1US5yY6NxHJBcct9fwYMk-zBGCIbIjFAe/view?usp=sharing)

---

<div class="post-metadata">

### Author: ![mihail.isakov](https://discourse.itk.org/letter_avatar_proxy/v4/letter/m/c4cdca/32.png) [@mihail.isakov](https://discourse.itk.org/u/mihail.isakov)
#### Post date: [October 15, 2025, 8:09pm UTC](https://discourse.itk.org/t/the-application-crashes-while-generating-the-nrrd-file/7646/3 "2025-10-15T20:09:27Z")

</div>

Adding

```cpp
    if (inOutBufferLength != len)
    {
      gdcmDebugMacro("inOutBufferLength = " << inOutBufferLength
                     << ", inBufferLength = " << inBufferLength << ", len = " << len);
      return false;
    }

```

after [line 119](https://github.com/issakomi/ITK/blob/cb07a31110216ac4b2e850a527188f30609cb4fa/Modules/ThirdParty/GDCM/src/gdcm/Source/MediaStorageAndFileFormat/gdcmRAWCodec.cxx#L119)  
` size_t len = str.size() * 16 / 12;`  
_ **may** _ work

Edit: added forgotten `;`

---

<div class="post-metadata">

### Author: ![purushothaman\_u](https://discourse.itk.org/user_avatar/discourse.itk.org/purushothaman_u/32/4593_2.png) [@purushothaman\_u](https://discourse.itk.org/u/purushothaman_u)
#### Post date: [October 16, 2025, 11:46am UTC](https://discourse.itk.org/t/the-application-crashes-while-generating-the-nrrd-file/7646/4 "2025-10-16T11:46:11Z")

</div>

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

---

<div class="post-metadata">

### Author: ![dzenanz](https://discourse.itk.org/user_avatar/discourse.itk.org/dzenanz/32/1093_2.png) [@dzenanz](https://discourse.itk.org/u/dzenanz)
#### Post date: [October 16, 2025, 2:48pm UTC](https://discourse.itk.org/t/the-application-crashes-while-generating-the-nrrd-file/7646/5 "2025-10-16T14:48:46Z")

</div>

@mathieu.malaterre Is this the correct solution?

@purushothaman_u you could make a PR to [GDCM](https://github.com/malaterre/GDCM).

---

<div class="post-metadata">

### Author: ![purushothaman\_u](https://discourse.itk.org/user_avatar/discourse.itk.org/purushothaman_u/32/4593_2.png) [@purushothaman\_u](https://discourse.itk.org/u/purushothaman_u)
#### Post date: [October 17, 2025, 8:05am UTC](https://discourse.itk.org/t/the-application-crashes-while-generating-the-nrrd-file/7646/6 "2025-10-17T08:05:04Z")

</div>

> <https://github.com/InsightSoftwareConsortium/ITK/pull/5561>
>
> \## PR Checklist
> \- \[x\] No \[API changes\](https://github.com/InsightSoftwareConsor…tium/ITK/blob/main/CONTRIBUTING.md#breaking-changes) were made (or the changes have been approved)
> \- \[x\] No \[major design changes\](https://github.com/InsightSoftwareConsortium/ITK/blob/main/CONTRIBUTING.md#design-changes) were made (or the changes have been approved)
> \- \[\] Added test (or behavior not changed)
> \- \[\] Updated API documentation (or API not changed)
> \- \[\] Added \[license\](https://github.com/InsightSoftwareConsortium/ITK/blob/main/Utilities/KWStyle/ITKHeader.h) to new files (if any)
> \- \[\] Added Python wrapping to new files (if any) as described in \[ITK Software Guide\](https://itk.org/ItkSoftwareGuide.pdf) Section 9.5
> \- \[\] Added \[ITK examples\](https://github.com/InsightSoftwareConsortium/ITKSphinxExamples) for all new major features (if any)
> 
> Refer to the \[ITK Software Guide\](https://itk.org/ItkSoftwareGuide.pdf) for
> further development details if necessary.

I have raised a PR.

---

<div class="post-metadata">

### Author: ![mathieu.malaterre](https://discourse.itk.org/user_avatar/discourse.itk.org/mathieu.malaterre/32/205_2.png) [@mathieu.malaterre](https://discourse.itk.org/u/mathieu.malaterre)
#### Post date: [October 17, 2025, 1:32pm UTC](https://discourse.itk.org/t/the-application-crashes-while-generating-the-nrrd-file/7646/7 "2025-10-17T13:32:19Z")

</div>

@purushothaman_u

I’ve added support for those fake 12bits allocated image upstream. Please see commit f57e45134ce6f0092687d0c4a69b5d7bee991dc5

Thanks
