The application crashes while generating the NRRD file

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

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

@mathieu.malaterre Is this the correct solution?

@purushothaman_u you could make a PR to GDCM.

I have raised a PR.

1 Like

@purushothaman_u

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

Thanks

1 Like