@@ -685,7 +685,7 @@ static INLINE OPJ_BOOL opj_tcd_init_tile(opj_tcd_t *p_tcd, OPJ_UINT32 p_tile_no,
685
685
/* room needed to store l_nb_code_blocks code blocks for a precinct*/
686
686
OPJ_UINT32 l_nb_code_blocks_size ;
687
687
/* size of data for a tile */
688
- OPJ_UINT32 l_data_size ;
688
+ size_t l_data_size ;
689
689
690
690
l_cp = p_tcd -> cp ;
691
691
l_tcp = & (l_cp -> tcps [p_tile_no ]);
@@ -726,18 +726,18 @@ static INLINE OPJ_BOOL opj_tcd_init_tile(opj_tcd_t *p_tcd, OPJ_UINT32 p_tile_no,
726
726
/*fprintf(stderr, "\tTile compo border = %d,%d,%d,%d\n", l_tilec->x0, l_tilec->y0,l_tilec->x1,l_tilec->y1);*/
727
727
728
728
/* compute l_data_size with overflow check */
729
- l_data_size = ( OPJ_UINT32 )( l_tilec -> x1 - l_tilec -> x0 ) ;
730
- if (((( OPJ_UINT32 ) - 1 ) / l_data_size ) < (OPJ_UINT32 )(l_tilec -> y1 - l_tilec -> y0 )) {
731
- opj_event_msg (manager , EVT_ERROR , "Not enough memory for tile data\n" );
729
+ l_data_size = l_tilec -> x1 - l_tilec -> x0 ;
730
+ if ((SIZE_MAX / l_data_size ) < (size_t )(l_tilec -> y1 - l_tilec -> y0 )) {
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 )( l_tilec -> y1 - l_tilec -> y0 );
734
+ l_data_size = l_data_size * (l_tilec -> y1 - l_tilec -> y0 );
735
735
736
- if (((( OPJ_UINT32 ) - 1 ) / ( OPJ_UINT32 ) sizeof (OPJ_UINT32 )) < l_data_size ) {
737
- opj_event_msg (manager , EVT_ERROR , "Not enough memory for tile data\n" );
736
+ if ((SIZE_MAX / sizeof (OPJ_UINT32 )) < l_data_size ) {
737
+ opj_event_msg (manager , EVT_ERROR , "Size of tile data exceeds system limits \n" );
738
738
return OPJ_FALSE ;
739
739
}
740
- l_data_size = l_data_size * ( OPJ_UINT32 ) sizeof (OPJ_UINT32 );
740
+ l_data_size = l_data_size * sizeof (OPJ_UINT32 );
741
741
l_tilec -> numresolutions = l_tccp -> numresolutions ;
742
742
if (l_tccp -> numresolutions < l_cp -> m_specific_param .m_dec .m_reduce ) {
743
743
l_tilec -> minimum_num_resolutions = 1 ;
@@ -752,14 +752,14 @@ static INLINE OPJ_BOOL opj_tcd_init_tile(opj_tcd_t *p_tcd, OPJ_UINT32 p_tile_no,
752
752
return OPJ_FALSE ;
753
753
}
754
754
755
- l_data_size = l_tilec -> numresolutions * ( OPJ_UINT32 ) sizeof (opj_tcd_resolution_t );
755
+ l_data_size = l_tilec -> numresolutions * sizeof (opj_tcd_resolution_t );
756
756
757
757
if (l_tilec -> resolutions == 00 ) {
758
758
l_tilec -> resolutions = (opj_tcd_resolution_t * ) opj_malloc (l_data_size );
759
759
if (! l_tilec -> resolutions ) {
760
760
return OPJ_FALSE ;
761
761
}
762
- /*fprintf(stderr, "\tAllocate resolutions of tilec (opj_tcd_resolution_t): %d \n",l_data_size);*/
762
+ /*fprintf(stderr, "\tAllocate resolutions of tilec (opj_tcd_resolution_t): %tu \n", l_data_size);*/
763
763
l_tilec -> resolutions_size = l_data_size ;
764
764
memset (l_tilec -> resolutions ,0 ,l_data_size );
765
765
}
@@ -773,7 +773,7 @@ static INLINE OPJ_BOOL opj_tcd_init_tile(opj_tcd_t *p_tcd, OPJ_UINT32 p_tile_no,
773
773
return OPJ_FALSE ;
774
774
}
775
775
l_tilec -> resolutions = new_resolutions ;
776
- /*fprintf(stderr, "\tReallocate data of tilec (int): from %d to %d x OPJ_UINT32\n", l_tilec->resolutions_size, l_data_size);*/
776
+ /*fprintf(stderr, "\tReallocate data of tilec (int): from %d to %tu x OPJ_UINT32\n", l_tilec->resolutions_size, l_data_size);*/
777
777
memset (((OPJ_BYTE * ) l_tilec -> resolutions )+ l_tilec -> resolutions_size ,0 ,l_data_size - l_tilec -> resolutions_size );
778
778
l_tilec -> resolutions_size = l_data_size ;
779
779
}
@@ -1069,9 +1069,9 @@ static OPJ_BOOL opj_tcd_code_block_enc_allocate (opj_tcd_cblk_enc_t * p_code_blo
1069
1069
*/
1070
1070
static OPJ_BOOL opj_tcd_code_block_enc_allocate_data (opj_tcd_cblk_enc_t * p_code_block )
1071
1071
{
1072
- OPJ_UINT32 l_data_size ;
1072
+ size_t l_data_size ;
1073
1073
1074
- 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 ));
1074
+ l_data_size = (size_t )((p_code_block -> x1 - p_code_block -> x0 ) * (p_code_block -> y1 - p_code_block -> y0 ) * sizeof (OPJ_UINT32 ));
1075
1075
1076
1076
if (l_data_size > p_code_block -> data_size ) {
1077
1077
if (p_code_block -> data ) {
0 commit comments