@@ -154,7 +154,9 @@ static bool is_big_endian(void)
154154static void byteswap (char * data , size_t length , size_t size )
155155{
156156 // only swap if the data is "swappable"
157- if (size > 0 && length >= size && length % size == 0 ) {
157+ if (size > 0 &&
158+ length >= size &&
159+ length % size == 0 ) {
158160 size_t n_elements = length / size ;
159161
160162 switch (size ) {
@@ -460,7 +462,8 @@ static bool parse_pixeldata_item(DcmParseState *state,
460462
461463 // native (not encapsulated) pixeldata is always little-endian and needs
462464 // byteswapping on big-endian machines
463- if (length != 0xffffffff && state -> big_endian ) {
465+ if (length != 0xffffffff &&
466+ state -> big_endian ) {
464467 byteswap (value , item_length , dcm_dict_vr_size (vr ));
465468 }
466469
@@ -588,7 +591,8 @@ static bool parse_element_body(DcmParseState *state,
588591 if (vr_class == DCM_VR_CLASS_NUMERIC_DECIMAL ||
589592 vr_class == DCM_VR_CLASS_NUMERIC_INTEGER ) {
590593 // all numeric classes have a size
591- if (length % size != 0 ) {
594+ if (size > 0 &&
595+ length % size != 0 ) {
592596 dcm_error_set (state -> error , DCM_ERROR_CODE_PARSE ,
593597 "reading of data element failed" ,
594598 "bad length for tag '%08x'" ,
0 commit comments