@@ -155,7 +155,7 @@ static bool is_big_endian(void)
155155static void byteswap (char * data , size_t length , size_t size )
156156{
157157 // only swap if the data is "swappable"
158- if (length >= size && length % size == 0 ) {
158+ if (size > 0 && length >= size && length % size == 0 ) {
159159 size_t n_elements = length / size ;
160160
161161 switch (size ) {
@@ -600,15 +600,15 @@ static bool parse_element_body(DcmParseState *state,
600600
601601 // read to a static char buffer, if possible
602602 if ((int64_t ) length + 1 >= INPUT_BUFFER_SIZE ) {
603- value = value_free = DCM_MALLOC (state -> error , (size_t ) length + 1 );
603+ value = value_free = DCM_MALLOC (state -> error ,
604+ (size_t ) length + 1 );
604605 if (value == NULL ) {
605606 return false;
606607 }
607608 } else {
608609 value = input_buffer ;
609610 }
610611
611-
612612 if (!dcm_require (state , value , length , position )) {
613613 if (value_free != NULL ) {
614614 free (value_free );
@@ -625,11 +625,8 @@ static bool parse_element_body(DcmParseState *state,
625625 }
626626 }
627627
628- if (vr_class == DCM_VR_CLASS_NUMERIC_DECIMAL ||
629- vr_class == DCM_VR_CLASS_NUMERIC_INTEGER ) {
630- if (state -> big_endian ) {
631- byteswap (value , length , size );
632- }
628+ if (size > 0 && state -> big_endian ) {
629+ byteswap (value , length , size );
633630 }
634631
635632 if (state -> parse -> element_create &&
0 commit comments