@@ -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,22 @@ 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 (l_data_size == 0 ) {
731
+ opj_event_msg (manager , EVT_ERROR , "Size of tile data is 0\n" );
732
+ return OPJ_FALSE ;
733
+ }
734
+ else if ((SIZE_MAX / l_data_size ) < (size_t )(l_tilec -> y1 - l_tilec -> y0 )) {
735
+ opj_event_msg (manager , EVT_ERROR , "Size of tile data exceeds system limits\n" );
732
736
return OPJ_FALSE ;
733
737
}
734
- l_data_size = l_data_size * (OPJ_UINT32 )( l_tilec -> y1 - l_tilec -> y0 );
738
+ l_data_size = l_data_size * (l_tilec -> y1 - l_tilec -> y0 );
735
739
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" );
740
+ if ((SIZE_MAX / sizeof (OPJ_UINT32 )) < l_data_size ) {
741
+ opj_event_msg (manager , EVT_ERROR , "Size of tile data exceeds system limits \n" );
738
742
return OPJ_FALSE ;
739
743
}
740
- l_data_size = l_data_size * ( OPJ_UINT32 ) sizeof (OPJ_UINT32 );
744
+ l_data_size = l_data_size * sizeof (OPJ_UINT32 );
741
745
l_tilec -> numresolutions = l_tccp -> numresolutions ;
742
746
if (l_tccp -> numresolutions < l_cp -> m_specific_param .m_dec .m_reduce ) {
743
747
l_tilec -> minimum_num_resolutions = 1 ;
@@ -752,14 +756,14 @@ static INLINE OPJ_BOOL opj_tcd_init_tile(opj_tcd_t *p_tcd, OPJ_UINT32 p_tile_no,
752
756
return OPJ_FALSE ;
753
757
}
754
758
755
- l_data_size = l_tilec -> numresolutions * ( OPJ_UINT32 ) sizeof (opj_tcd_resolution_t );
759
+ l_data_size = l_tilec -> numresolutions * sizeof (opj_tcd_resolution_t );
756
760
757
761
if (l_tilec -> resolutions == 00 ) {
758
762
l_tilec -> resolutions = (opj_tcd_resolution_t * ) opj_malloc (l_data_size );
759
763
if (! l_tilec -> resolutions ) {
760
764
return OPJ_FALSE ;
761
765
}
762
- /*fprintf(stderr, "\tAllocate resolutions of tilec (opj_tcd_resolution_t): %d \n",l_data_size);*/
766
+ /*fprintf(stderr, "\tAllocate resolutions of tilec (opj_tcd_resolution_t): %tu \n", l_data_size);*/
763
767
l_tilec -> resolutions_size = l_data_size ;
764
768
memset (l_tilec -> resolutions ,0 ,l_data_size );
765
769
}
@@ -773,7 +777,7 @@ static INLINE OPJ_BOOL opj_tcd_init_tile(opj_tcd_t *p_tcd, OPJ_UINT32 p_tile_no,
773
777
return OPJ_FALSE ;
774
778
}
775
779
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);*/
780
+ /*fprintf(stderr, "\tReallocate data of tilec (int): from %d to %tu x OPJ_UINT32\n", l_tilec->resolutions_size, l_data_size);*/
777
781
memset (((OPJ_BYTE * ) l_tilec -> resolutions )+ l_tilec -> resolutions_size ,0 ,l_data_size - l_tilec -> resolutions_size );
778
782
l_tilec -> resolutions_size = l_data_size ;
779
783
}
@@ -1069,9 +1073,9 @@ static OPJ_BOOL opj_tcd_code_block_enc_allocate (opj_tcd_cblk_enc_t * p_code_blo
1069
1073
*/
1070
1074
static OPJ_BOOL opj_tcd_code_block_enc_allocate_data (opj_tcd_cblk_enc_t * p_code_block )
1071
1075
{
1072
- OPJ_UINT32 l_data_size ;
1076
+ size_t l_data_size ;
1073
1077
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 ));
1078
+ 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
1079
1076
1080
if (l_data_size > p_code_block -> data_size ) {
1077
1081
if (p_code_block -> data ) {
0 commit comments