Skip to content

Commit acd37a1

Browse files
DICOM reader: better handling of nested sequences that include pixel data
Fixes #4165.
1 parent 83df5ca commit acd37a1

1 file changed

Lines changed: 22 additions & 3 deletions

File tree

components/formats-bsd/src/loci/formats/dicom/DicomTag.java

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -310,15 +310,33 @@ else if (elementLength <= 44) {
310310
break;
311311
}
312312
else if (child.attribute == PIXEL_DATA) {
313-
stop = fp;
314-
break;
313+
child.parent = this;
314+
children.add(child);
315+
if (child.elementLength == -1) {
316+
// look for end of sequence
317+
long seek = fp - 2;
318+
int nextTag = 0;
319+
while (seek < in.length() && (nextTag != SEQUENCE_DELIMITATION_ITEM.getTag() && nextTag != ITEM_DELIMITATION_ITEM.getTag())) {
320+
seek += 2;
321+
in.seek(seek);
322+
try {
323+
nextTag = getNextTag(in);
324+
}
325+
catch (Exception e) {
326+
}
327+
if (nextTag == 0xfeffdde0 || nextTag == 0xfeff0d0e) {
328+
in.order(!in.isLittleEndian());
329+
break;
330+
}
331+
}
332+
}
315333
}
316334
else if (child.attribute != ITEM && child.attribute != ITEM_DELIMITATION_ITEM) {
317335
child.parent = this;
318336
children.add(child);
319337
}
320338
}
321-
if (elementLength == 0) {
339+
if (elementLength <= 0) {
322340
elementLength = (int) (stop - start);
323341
}
324342
in.seek(stop);
@@ -438,6 +456,7 @@ private int getLength(RandomAccessInputStream in) throws IOException {
438456

439457
switch (vr) {
440458
case OB:
459+
case OV:
441460
case OW:
442461
case SQ:
443462
case UN:

0 commit comments

Comments
 (0)