Skip to content

Commit 6523a07

Browse files
committed
test_tile_encoder: Fix potential buffer overflow (coverity)
CID 1190154 (uclouvain#1 of 1): Unbounded source buffer (STRING_SIZE) Using a pointer instead of buffer of fixed size avoids the limit for the length of the output file name. This implies that the length can exceed 255, so the data type for variable len had to be fixed, too. Signed-off-by: Stefan Weil <[email protected]>
1 parent 94234bd commit 6523a07

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

tests/test_tile_encoder.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ int main (int argc, char *argv[])
6969
opj_stream_t * l_stream;
7070
OPJ_UINT32 l_nb_tiles;
7171
OPJ_UINT32 l_data_size;
72-
unsigned char len;
72+
size_t len;
7373

7474
#ifdef USING_MCT
7575
const OPJ_FLOAT32 l_mct [] =
@@ -96,7 +96,7 @@ int main (int argc, char *argv[])
9696
int tile_height;
9797
int comp_prec;
9898
int irreversible;
99-
char output_file[64];
99+
const char *output_file;
100100

101101
/* should be test_tile_encoder 3 2000 2000 1000 1000 8 tte1.j2k */
102102
if( argc == 9 )
@@ -108,7 +108,7 @@ int main (int argc, char *argv[])
108108
tile_height = atoi( argv[5] );
109109
comp_prec = atoi( argv[6] );
110110
irreversible = atoi( argv[7] );
111-
strcpy(output_file, argv[8] );
111+
output_file = argv[8];
112112
}
113113
else
114114
{
@@ -119,7 +119,7 @@ int main (int argc, char *argv[])
119119
tile_height = 1000;
120120
comp_prec = 8;
121121
irreversible = 1;
122-
strcpy(output_file, "test.j2k" );
122+
output_file = "test.j2k";
123123
}
124124
if( num_comps > NUM_COMPS_MAX )
125125
{
@@ -228,7 +228,7 @@ int main (int argc, char *argv[])
228228
}
229229

230230
/* should we do j2k or jp2 ?*/
231-
len = (unsigned char)strlen( output_file );
231+
len = strlen( output_file );
232232
if( strcmp( output_file + len - 4, ".jp2" ) == 0 )
233233
{
234234
l_codec = opj_create_compress(OPJ_CODEC_JP2);

0 commit comments

Comments
 (0)