@@ -678,7 +678,7 @@ static INLINE OPJ_BOOL opj_tcd_init_tile(opj_tcd_t *p_tcd, OPJ_UINT32 p_tile_no,
678
678
/* room needed to store l_nb_code_blocks code blocks for a precinct*/
679
679
OPJ_UINT32 l_nb_code_blocks_size ;
680
680
/* size of data for a tile */
681
- OPJ_UINT32 l_data_size ;
681
+ size_t l_data_size ;
682
682
683
683
l_cp = p_tcd -> cp ;
684
684
l_tcp = & (l_cp -> tcps [p_tile_no ]);
@@ -719,19 +719,19 @@ static INLINE OPJ_BOOL opj_tcd_init_tile(opj_tcd_t *p_tcd, OPJ_UINT32 p_tile_no,
719
719
/*fprintf(stderr, "\tTile compo border = %d,%d,%d,%d\n", l_tilec->x0, l_tilec->y0,l_tilec->x1,l_tilec->y1);*/
720
720
721
721
/* compute l_data_size with overflow check */
722
- l_data_size = ( OPJ_UINT32 )( l_tilec -> x1 - l_tilec -> x0 ) ;
722
+ l_data_size = l_tilec -> x1 - l_tilec -> x0 ;
723
723
/* issue 733, l_data_size == 0U, probably something wrong should be checked before getting here */
724
- if ((l_data_size > 0U ) && (((( OPJ_UINT32 ) - 1 ) / l_data_size ) < (OPJ_UINT32 )(l_tilec -> y1 - l_tilec -> y0 ))) {
724
+ if ((l_data_size > 0U ) && ((SIZE_MAX / l_data_size ) < (size_t )(l_tilec -> y1 - l_tilec -> y0 ))) {
725
725
opj_event_msg (manager , EVT_ERROR , "Not enough memory for tile data\n" );
726
726
return OPJ_FALSE ;
727
727
}
728
- l_data_size = l_data_size * (OPJ_UINT32 )( l_tilec -> y1 - l_tilec -> y0 );
728
+ l_data_size = l_data_size * (l_tilec -> y1 - l_tilec -> y0 );
729
729
730
- if (((( OPJ_UINT32 ) - 1 ) / ( OPJ_UINT32 ) sizeof (OPJ_UINT32 )) < l_data_size ) {
731
- opj_event_msg (manager , EVT_ERROR , "Not enough memory for tile data\n" );
730
+ if ((SIZE_MAX / sizeof (OPJ_UINT32 )) < l_data_size ) {
731
+ opj_event_msg (manager , EVT_ERROR , "Size of tile data exceeds system limits \n" );
732
732
return OPJ_FALSE ;
733
733
}
734
- l_data_size = l_data_size * ( OPJ_UINT32 ) sizeof (OPJ_UINT32 );
734
+ l_data_size = l_data_size * sizeof (OPJ_UINT32 );
735
735
l_tilec -> numresolutions = l_tccp -> numresolutions ;
736
736
if (l_tccp -> numresolutions < l_cp -> m_specific_param .m_dec .m_reduce ) {
737
737
l_tilec -> minimum_num_resolutions = 1 ;
@@ -746,14 +746,14 @@ static INLINE OPJ_BOOL opj_tcd_init_tile(opj_tcd_t *p_tcd, OPJ_UINT32 p_tile_no,
746
746
return OPJ_FALSE ;
747
747
}
748
748
749
- l_data_size = l_tilec -> numresolutions * ( OPJ_UINT32 ) sizeof (opj_tcd_resolution_t );
749
+ l_data_size = l_tilec -> numresolutions * sizeof (opj_tcd_resolution_t );
750
750
751
751
if (l_tilec -> resolutions == 00 ) {
752
752
l_tilec -> resolutions = (opj_tcd_resolution_t * ) opj_malloc (l_data_size );
753
753
if (! l_tilec -> resolutions ) {
754
754
return OPJ_FALSE ;
755
755
}
756
- /*fprintf(stderr, "\tAllocate resolutions of tilec (opj_tcd_resolution_t): %d \n",l_data_size);*/
756
+ /*fprintf(stderr, "\tAllocate resolutions of tilec (opj_tcd_resolution_t): %tu \n", l_data_size);*/
757
757
l_tilec -> resolutions_size = l_data_size ;
758
758
memset (l_tilec -> resolutions ,0 ,l_data_size );
759
759
}
@@ -767,7 +767,7 @@ static INLINE OPJ_BOOL opj_tcd_init_tile(opj_tcd_t *p_tcd, OPJ_UINT32 p_tile_no,
767
767
return OPJ_FALSE ;
768
768
}
769
769
l_tilec -> resolutions = new_resolutions ;
770
- /*fprintf(stderr, "\tReallocate data of tilec (int): from %d to %d x OPJ_UINT32\n", l_tilec->resolutions_size, l_data_size);*/
770
+ /*fprintf(stderr, "\tReallocate data of tilec (int): from %d to %tu x OPJ_UINT32\n", l_tilec->resolutions_size, l_data_size);*/
771
771
memset (((OPJ_BYTE * ) l_tilec -> resolutions )+ l_tilec -> resolutions_size ,0 ,l_data_size - l_tilec -> resolutions_size );
772
772
l_tilec -> resolutions_size = l_data_size ;
773
773
}
@@ -1064,9 +1064,9 @@ static OPJ_BOOL opj_tcd_code_block_enc_allocate (opj_tcd_cblk_enc_t * p_code_blo
1064
1064
*/
1065
1065
static OPJ_BOOL opj_tcd_code_block_enc_allocate_data (opj_tcd_cblk_enc_t * p_code_block )
1066
1066
{
1067
- OPJ_UINT32 l_data_size ;
1067
+ size_t l_data_size ;
1068
1068
1069
- l_data_size = (OPJ_UINT32 )((p_code_block -> x1 - p_code_block -> x0 ) * (p_code_block -> y1 - p_code_block -> y0 ) * ( OPJ_INT32 ) sizeof (OPJ_UINT32 ));
1069
+ l_data_size = (size_t )((p_code_block -> x1 - p_code_block -> x0 ) * (p_code_block -> y1 - p_code_block -> y0 ) * sizeof (OPJ_UINT32 ));
1070
1070
1071
1071
if (l_data_size > p_code_block -> data_size ) {
1072
1072
if (p_code_block -> data ) {
0 commit comments