Skip to content

Commit 9cb222d

Browse files
committed
simplify first BOT offset calculation
restore some error handling
1 parent 2c33aa4 commit 9cb222d

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

src/dicom-parse.c

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -955,12 +955,10 @@ bool dcm_parse_pixeldata_offsets(DcmError **error,
955955
// each frame
956956

957957
dcm_log_info("building Offset Table from Pixel Data");
958-
// by definition the first offset is 0
959-
offsets[0] = 0;
960958

961959
// 0 in the BOT is the offset to the start of frame 1, ie. here
962960
*first_frame_offset = position;
963-
for (int i = 1; i < num_frames; i++) {
961+
for (int i = 0; i < num_frames; i++) {
964962
if (!read_tag(&state, &tag, &position) ||
965963
!read_uint32(&state, &length, &position)) {
966964
return false;
@@ -983,13 +981,25 @@ bool dcm_parse_pixeldata_offsets(DcmError **error,
983981
}
984982

985983
// step back to the start of the item for this frame
986-
offsets[i] = position - 8;
984+
offsets[i] = position - *first_frame_offset - 8;
987985

988986
// and seek forward over the value
989987
if (!dcm_seekcur(&state, length, &position)) {
990988
return false;
991989
}
992990
}
991+
992+
// in case multiple frames 1:1 frame to fragment mapping is assumed,
993+
// therefore the next thing should be the end of sequence tag
994+
if (!read_tag(&state, &tag, &position)) {
995+
return false;
996+
}
997+
if (num_frames != 1 && tag != TAG_SQ_DELIM) {
998+
dcm_error_set(error, DCM_ERROR_CODE_PARSE,
999+
"reading BasicOffsetTable failed",
1000+
"too many frames in PixelData");
1001+
return false;
1002+
}
9931003
}
9941004

9951005
return true;

0 commit comments

Comments
 (0)