Skip to content

Commit adbe9ec

Browse files
authored
Merge pull request #70 from bgilbert/fixes
Fix a crash and some error pile-ups on invalid files
2 parents 2ea0713 + 32f0c40 commit adbe9ec

File tree

2 files changed

+18
-11
lines changed

2 files changed

+18
-11
lines changed

src/dicom-file.c

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -536,7 +536,7 @@ static DcmDataSet *dcm_filehandle_read_file_meta(DcmError **error,
536536
false,
537537
&parse,
538538
filehandle)) {
539-
return false;
539+
return NULL;
540540
}
541541

542542
/* Sanity check. We should have parsed a single dataset into the sequence
@@ -555,8 +555,8 @@ static DcmDataSet *dcm_filehandle_read_file_meta(DcmError **error,
555555
}
556556

557557
DcmDataSet *file_meta = dcm_sequence_get(error, sequence, 0);
558-
if (file_meta == NULL ) {
559-
return false;
558+
if (file_meta == NULL) {
559+
return NULL;
560560
}
561561

562562
// steal file_meta to stop it being destroyed
@@ -765,7 +765,7 @@ DcmDataSet *dcm_filehandle_read_metadata(DcmError **error,
765765
filehandle->implicit,
766766
&parse,
767767
filehandle)) {
768-
return false;
768+
return NULL;
769769
}
770770

771771
/* Sanity check. We should have parsed a single dataset into the sequence
@@ -784,8 +784,8 @@ DcmDataSet *dcm_filehandle_read_metadata(DcmError **error,
784784
}
785785

786786
DcmDataSet *meta = dcm_sequence_get(error, sequence, 0);
787-
if (meta == NULL ) {
788-
return false;
787+
if (meta == NULL) {
788+
return NULL;
789789
}
790790

791791
// steal meta to stop it being destroyed
@@ -821,6 +821,9 @@ const DcmDataSet *dcm_filehandle_get_metadata_subset(DcmError **error,
821821
DcmDataSet *meta = dcm_filehandle_read_metadata(error,
822822
filehandle,
823823
stop_tags);
824+
if (meta == NULL) {
825+
return NULL;
826+
}
824827

825828
// record the position of the tag that stopped the read
826829
if (!dcm_offset(error, filehandle, &filehandle->after_read_metadata)) {
@@ -838,7 +841,7 @@ const DcmDataSet *dcm_filehandle_get_metadata_subset(DcmError **error,
838841
&filehandle->tiles_across, &filehandle->tiles_down) ||
839842
!set_pixel_description(error, meta, &filehandle->desc)) {
840843
dcm_dataset_destroy(meta);
841-
return false;
844+
return NULL;
842845
}
843846
filehandle->num_tiles = filehandle->tiles_across *
844847
filehandle->tiles_down;

src/dicom-parse.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -940,8 +940,10 @@ bool dcm_parse_pixeldata_offsets(DcmError **error,
940940
*first_frame_offset = position;
941941

942942
// the next thing should be the tag for frame 1
943-
if (!read_tag(&state, &tag, &position) ||
944-
tag != TAG_ITEM) {
943+
if (!read_tag(&state, &tag, &position)) {
944+
return false;
945+
}
946+
if (tag != TAG_ITEM) {
945947
dcm_error_set(error, DCM_ERROR_CODE_PARSE,
946948
"Reading Basic Offset Table failed",
947949
"Basic Offset Table too large");
@@ -990,8 +992,10 @@ bool dcm_parse_pixeldata_offsets(DcmError **error,
990992
}
991993

992994
// the next thing should be the end of sequence tag
993-
if (!read_tag(&state, &tag, &position) ||
994-
tag != TAG_SQ_DELIM) {
995+
if (!read_tag(&state, &tag, &position)) {
996+
return false;
997+
}
998+
if (tag != TAG_SQ_DELIM) {
995999
dcm_error_set(error, DCM_ERROR_CODE_PARSE,
9961000
"Reading Basic Offset Table failed",
9971001
"Too many frames in PixelData");

0 commit comments

Comments
 (0)