@@ -954,11 +954,14 @@ bool dcm_parse_pixeldata_offsets(DcmError **error,
954954 // the BOT is missing, we must scan pixeldata to find the position of
955955 // each frame
956956
957+ // we could use our generic parser above ^^ but we have a special loop
958+ // here as an optimisation (we can skip over the pixel data itself)
959+
957960 dcm_log_info ("building Offset Table from Pixel Data" );
958961
959962 // 0 in the BOT is the offset to the start of frame 1, ie. here
960963 * first_frame_offset = position ;
961- for (int i = 0 ; i < num_frames ; i ++ ) {
964+ for (int i = 0 ; i < num_frames ; i ++ ) {
962965 if (!read_tag (& state , & tag , & position ) ||
963966 !read_uint32 (& state , & length , & position )) {
964967 return false;
@@ -1019,7 +1022,10 @@ char *dcm_parse_frame(DcmError **error,
10191022 .big_endian = is_big_endian (),
10201023 };
10211024
1022- * length = desc -> rows * desc -> columns * desc -> samples_per_pixel * (desc -> bits_allocated / 8 );
1025+ * length = desc -> rows *
1026+ desc -> columns *
1027+ desc -> samples_per_pixel *
1028+ (desc -> bits_allocated / 8 );
10231029
10241030 char * value = DCM_MALLOC (error , * length );
10251031 if (value == NULL ) {
@@ -1037,10 +1043,10 @@ char *dcm_parse_frame(DcmError **error,
10371043/* Read encapsulated frame. Return NULL in case of error.
10381044*/
10391045char * dcm_parse_encapsulated_frame (DcmError * * error ,
1040- DcmIO * io ,
1041- bool implicit ,
1042- int64_t frame_end_offset ,
1043- uint32_t * length )
1046+ DcmIO * io ,
1047+ bool implicit ,
1048+ int64_t frame_end_offset ,
1049+ uint32_t * length )
10441050{
10451051 DcmParseState state = {
10461052 .error = error ,
@@ -1056,7 +1062,7 @@ char *dcm_parse_encapsulated_frame(DcmError **error,
10561062 uint64_t frame_length = 0 ;
10571063
10581064 // first determine the total length of bytes to be read
1059- while (position < frame_end_offset ) {
1065+ while (position < frame_end_offset ) {
10601066 if (!read_tag (& state , & tag , & position )) {
10611067 return NULL ;
10621068 }
@@ -1075,7 +1081,10 @@ char *dcm_parse_encapsulated_frame(DcmError **error,
10751081 dcm_seekcur (& state , fragment_length , & position );
10761082 frame_length += fragment_length ;
10771083 }
1078- if ( frame_length > 0xFFFFFFFF ) {
1084+ if (frame_length > 0xFFFFFFFF ) {
1085+ dcm_error_set (error , DCM_ERROR_CODE_PARSE ,
1086+ "invalid frame size" ,
1087+ "frame size exceeds 4GB" );
10791088 return NULL ;
10801089 }
10811090
@@ -1093,7 +1102,7 @@ char *dcm_parse_encapsulated_frame(DcmError **error,
10931102 fragment_length = 0 ;
10941103 char * fragment = value ;
10951104 position = 0 ;
1096- while (position < frame_end_offset ) {
1105+ while (position < frame_end_offset ) {
10971106 read_tag (& state , & tag , & position );
10981107 read_uint32 (& state , & fragment_length , & position );
10991108 if (!dcm_require (& state , fragment , fragment_length , & position )) {
0 commit comments