@@ -973,7 +973,7 @@ bool dcm_parse_pixeldata_offsets(DcmError **error,
973973 "too few frames in PixelData" );
974974 return false;
975975 }
976-
976+
977977 if (tag != TAG_ITEM ) {
978978 dcm_error_set (error , DCM_ERROR_CODE_PARSE ,
979979 "building BasicOffsetTable failed" ,
@@ -982,10 +982,10 @@ bool dcm_parse_pixeldata_offsets(DcmError **error,
982982 tag );
983983 return false;
984984 }
985-
985+
986986 // step back to the start of the item for this frame
987987 offsets [i ] = position - * first_frame_offset - 8 ;
988-
988+
989989 // and seek forward over the value
990990 if (!dcm_seekcur (& state , length , & position )) {
991991 return false;
@@ -1041,7 +1041,7 @@ char *dcm_parse_frame(DcmError **error,
10411041}
10421042
10431043/* Read encapsulated frame. Return NULL in case of error.
1044- */
1044+ */
10451045char * dcm_parse_encapsulated_frame (DcmError * * error ,
10461046 DcmIO * io ,
10471047 bool implicit ,
@@ -1103,14 +1103,20 @@ char *dcm_parse_encapsulated_frame(DcmError **error,
11031103 char * fragment = value ;
11041104 position = 0 ;
11051105 while (position < frame_end_offset ) {
1106- read_tag (& state , & tag , & position );
1107- read_uint32 (& state , & fragment_length , & position );
1108- if (!dcm_require (& state , fragment , fragment_length , & position )) {
1106+ if (!read_tag (& state , & tag , & position )) {
1107+ return NULL ;
1108+ }
1109+ if (tag == TAG_SQ_DELIM ) {
1110+ break ;
1111+ }
1112+ if (!read_uint32 (& state , & fragment_length , & position ) ||
1113+ !dcm_require (& state , fragment , fragment_length , & position )) {
11091114 free (value );
11101115 return NULL ;
11111116 }
11121117 fragment += fragment_length ;
11131118 }
11141119 * length = (uint32_t ) frame_length ;
1120+
11151121 return value ;
11161122}
0 commit comments