dicomParser skips PixelData if it can not determine the length of an unknown tag
I have an issue with a dicom file that has an unknown tag before Pixel Data. dicomParser tries to determine the length of this unknown tag and checks only ItemDelimitationItem (fffe, e00d), not SequenceDelimitationItem (fffe, e0dd), so it can not determine its length and sets its length to the end of the buffer, so skips Pixel Data.
My quick fix is that i check SequenceDelimitationItem in findItemDelimitationItemAndSetElementLength, but not sure if that is a good fix.
if(elementNumber === 0xe00d || elementNumber === 0xe0dd) { ... }
This is the end of its dicom dump which shows the unknown tag and Pixel Data:
(0507,1001) SQ (Sequence with undefined length #=1) # u/l, 1 Unknown Tag & Data (fffe,e000) na (Item with explicit length #=8) # 74, 1 Item (0507,0000) UL 62 # 4, 1 PrivateGroupLength (0507,1002) ?? (no value available) # 0, 1 Unknown Tag & Data (0507,1003) ?? (no value available) # 0, 1 Unknown Tag & Data (0507,1004) ?? (no value available) # 0, 1 Unknown Tag & Data (0507,1005) ?? 30\20 # 2, 1 Unknown Tag & Data (0507,1006) ?? 30\20 # 2, 1 Unknown Tag & Data (0507,1007) ?? (no value available) # 0, 1 Unknown Tag & Data (0507,1008) ?? 30\20 # 2, 1 Unknown Tag & Data (fffe,e00d) na (ItemDelimitationItem for re-encoding) # 0, 0 ItemDelimitationItem (fffe,e0dd) na (SequenceDelimitationItem) # 0, 0 SequenceDelimitationItem (7fe0,0010) OB (PixelSequence #=2) # u/l, 1 PixelData (fffe,e000) pi (no value available) # 0, 1 Item (fffe,e000) pi ff\d8\ff\c3\00\0b\10\06\01\03\04\01\00\11\00\ff\c4\00\24\00\00\00... # 1250014, 1 Item (fffe,e0dd) na (SequenceDelimitationItem) # 0, 0 SequenceDelimitationItem
I can not share the file, because anonymization tools remove that unknown tag.
I don't think that's the fix we want. I'm actually not sure how dicomParser is even getting into findItemDelimitationItemAndSetElementLength. It shouldn't be using that on the SQ element, only on individual items. Do you know?
It's hard to tell from just the dump, but it looks like that item has an explicitly-defined length of 8 bytes, which wouldn't even cover the (0507,0000) element. If that's the case, per the standard there wouldn't even be an item delimitation item and dicomParser should be throwing an exception when it looks for a second item and doesn't find the item tag (see readSequenceItem). That would mean the file isn't standard-compliant.
This sounds like an invalid DICOM file, especially if anonymization tools remove the tag. Your fix may solve your problem, but it would make the library non standards compliant so is not an acceptable change for the library. My general philosophy is to keep the library standards compliant but provide hooks when possible for higher levels to implement workarounds for non standard data. Unfortunately I can't really suggest any hooks for a workaround without looking at the file itself
This is the (0507,1001) element it reads: { "tag": "x05071001", "vr": "UN", "length": 4294967295, "dataOffset": 2384 }
Its VR is not SQ and it has undefined length, so that is why it is getting in findItemDelimitationItemAndSetElementLength.
Rereading the DICOM standard on undefined length handling and it looks like we have the logic wrong for non SQ elements. Use of undefined length appears to be restricted to specific VR's and is also parsed in the same way as a SQ element. I need to find some data sets that have this condition so I can verify a fix, if anyone has an anonymized one please send it my way :)
Just pushed version 1.7.3 which should fix this - can you please test and confirm? Your workaround fix is not correct
actually test 1.7.4, a bug slipped into 1.7.3 on accident :(
1.7.4 works fine for that case