openjpeg2/SOURCES/openjpeg2_coverity.patch
2021-09-09 23:13:34 +00:00

279 lines
9.0 KiB
Diff

diff --git a/src/bin/jp2/convert.c b/src/bin/jp2/convert.c
index 0b17602..34603eb 100644
--- a/src/bin/jp2/convert.c
+++ b/src/bin/jp2/convert.c
@@ -1416,6 +1416,9 @@ int imagetopgx(opj_image_t * image, const char *outfile)
unsigned char* line_buffer = malloc((size_t)w);
if (line_buffer == NULL) {
fprintf(stderr, "Out of memory");
+ if (total > 256) {
+ free(name);
+ }
goto fin;
}
for (j = 0; j < h; j++) {
diff --git a/src/bin/jp2/opj_compress.c b/src/bin/jp2/opj_compress.c
index 26454d9..e21431b 100644
--- a/src/bin/jp2/opj_compress.c
+++ b/src/bin/jp2/opj_compress.c
@@ -1739,6 +1739,8 @@ int main(int argc, char **argv)
img_fol_t img_fol;
dircnt_t *dirptr = NULL;
+ int ret;
+
OPJ_BOOL bSuccess;
OPJ_BOOL bUseTiles = OPJ_FALSE; /* OPJ_TRUE */
OPJ_UINT32 l_nb_tiles = 4;
@@ -1764,7 +1766,8 @@ int main(int argc, char **argv)
255; /* This will be set later according to the input image or the provided option */
if (parse_cmdline_encoder(argc, argv, &parameters, &img_fol, &raw_cp,
indexfilename, sizeof(indexfilename)) == 1) {
- goto fails;
+ ret = 1;
+ goto end;
}
/* Read directory if necessary */
@@ -1776,18 +1779,21 @@ int main(int argc, char **argv)
char)); /* Stores at max 10 image file names*/
dirptr->filename = (char**) malloc(num_images * sizeof(char*));
if (!dirptr->filename_buf) {
- return 0;
+ ret = 0;
+ goto end;
}
for (i = 0; i < num_images; i++) {
dirptr->filename[i] = dirptr->filename_buf + i * OPJ_PATH_LEN;
}
}
if (load_images(dirptr, img_fol.imgdirpath) == 1) {
- return 0;
+ ret = 0;
+ goto end;
}
if (num_images == 0) {
fprintf(stdout, "Folder is empty\n");
- return 0;
+ ret = 0;
+ goto end;
}
} else {
num_images = 1;
@@ -1833,7 +1839,8 @@ int main(int argc, char **argv)
image = pgxtoimage(parameters.infile, &parameters);
if (!image) {
fprintf(stderr, "Unable to load pgx file\n");
- return 1;
+ ret = 1;
+ goto end;
}
break;
@@ -1841,7 +1848,8 @@ int main(int argc, char **argv)
image = pnmtoimage(parameters.infile, &parameters);
if (!image) {
fprintf(stderr, "Unable to load pnm file\n");
- return 1;
+ ret = 1;
+ goto end;
}
break;
@@ -1849,7 +1857,8 @@ int main(int argc, char **argv)
image = bmptoimage(parameters.infile, &parameters);
if (!image) {
fprintf(stderr, "Unable to load bmp file\n");
- return 1;
+ ret = 1;
+ goto end;
}
break;
@@ -1858,7 +1867,8 @@ int main(int argc, char **argv)
image = tiftoimage(parameters.infile, &parameters);
if (!image) {
fprintf(stderr, "Unable to load tiff file\n");
- return 1;
+ ret = 1;
+ goto end;
}
break;
#endif /* OPJ_HAVE_LIBTIFF */
@@ -1867,7 +1877,8 @@ int main(int argc, char **argv)
image = rawtoimage(parameters.infile, &parameters, &raw_cp);
if (!image) {
fprintf(stderr, "Unable to load raw file\n");
- return 1;
+ ret = 1;
+ goto end;
}
break;
@@ -1875,7 +1886,8 @@ int main(int argc, char **argv)
image = rawltoimage(parameters.infile, &parameters, &raw_cp);
if (!image) {
fprintf(stderr, "Unable to load raw file\n");
- return 1;
+ ret = 1;
+ goto end;
}
break;
@@ -1883,7 +1895,8 @@ int main(int argc, char **argv)
image = tgatoimage(parameters.infile, &parameters);
if (!image) {
fprintf(stderr, "Unable to load tga file\n");
- return 1;
+ ret = 1;
+ goto end;
}
break;
@@ -1892,7 +1905,8 @@ int main(int argc, char **argv)
image = pngtoimage(parameters.infile, &parameters);
if (!image) {
fprintf(stderr, "Unable to load png file\n");
- return 1;
+ ret = 1;
+ goto end;
}
break;
#endif /* OPJ_HAVE_LIBPNG */
@@ -1903,7 +1917,8 @@ int main(int argc, char **argv)
*/
if (!image) {
fprintf(stderr, "Unable to load file: got no image\n");
- return 1;
+ ret = 1;
+ goto end;
}
/* Decide if MCT should be used */
@@ -1914,12 +1929,14 @@ int main(int argc, char **argv)
if ((parameters.tcp_mct == 1) && (image->numcomps < 3)) {
fprintf(stderr, "RGB->YCC conversion cannot be used:\n");
fprintf(stderr, "Input image has less than 3 components\n");
- return 1;
+ ret = 1;
+ goto end;
}
if ((parameters.tcp_mct == 2) && (!parameters.mct_data)) {
fprintf(stderr, "Custom MCT has been set but no array-based MCT\n");
fprintf(stderr, "has been provided. Aborting.\n");
- return 1;
+ ret = 1;
+ goto end;
}
}
@@ -1959,13 +1976,15 @@ int main(int argc, char **argv)
fprintf(stderr, "failed to encode image: opj_setup_encoder\n");
opj_destroy_codec(l_codec);
opj_image_destroy(image);
- return 1;
+ ret = 1;
+ goto end;
}
/* open a byte stream for writing and allocate memory for all tiles */
l_stream = opj_stream_create_default_file_stream(parameters.outfile, OPJ_FALSE);
if (! l_stream) {
- return 1;
+ ret = 1;
+ goto end;
}
/* encode the image */
@@ -1978,7 +1997,8 @@ int main(int argc, char **argv)
OPJ_UINT32 l_data_size = 512 * 512 * 3;
l_data = (OPJ_BYTE*) calloc(1, l_data_size);
if (l_data == NULL) {
- goto fails;
+ ret = 1;
+ goto end;
}
for (i = 0; i < l_nb_tiles; ++i) {
if (! opj_write_tile(l_codec, i, l_data, l_data_size, l_stream)) {
@@ -1987,7 +2007,8 @@ int main(int argc, char **argv)
opj_stream_destroy(l_stream);
opj_destroy_codec(l_codec);
opj_image_destroy(image);
- return 1;
+ ret = 1;
+ goto end;
}
}
free(l_data);
@@ -2008,7 +2029,8 @@ int main(int argc, char **argv)
opj_image_destroy(image);
fprintf(stderr, "failed to encode image\n");
remove(parameters.outfile);
- return 1;
+ ret = 1;
+ goto end;
}
num_compressed_files++;
@@ -2024,26 +2046,15 @@ int main(int argc, char **argv)
}
- /* free user parameters structure */
- if (parameters.cp_comment) {
- free(parameters.cp_comment);
- }
- if (parameters.cp_matrice) {
- free(parameters.cp_matrice);
- }
- if (raw_cp.rawComps) {
- free(raw_cp.rawComps);
- }
-
t = opj_clock() - t;
if (num_compressed_files) {
fprintf(stdout, "encode time: %d ms \n",
(int)((t * 1000.0) / (OPJ_FLOAT64)num_compressed_files));
}
- return 0;
+ ret = 0;
-fails:
+end:
if (parameters.cp_comment) {
free(parameters.cp_comment);
}
@@ -2065,5 +2076,5 @@ fails:
}
free(dirptr);
}
- return 1;
+ return ret;
}
diff --git a/src/lib/openjp2/dwt.c b/src/lib/openjp2/dwt.c
index 5b98d2b..17021de 100644
--- a/src/lib/openjp2/dwt.c
+++ b/src/lib/openjp2/dwt.c
@@ -2696,17 +2696,20 @@ OPJ_BOOL opj_dwt_decode_partial_97(opj_tcd_tilecomp_t* OPJ_RESTRICT tilec,
/* overflow check */
if (l_data_size > (SIZE_MAX - 5U)) {
/* FIXME event manager error callback */
+ opj_sparse_array_int32_free(sa);
return OPJ_FALSE;
}
l_data_size += 5U;
/* overflow check */
if (l_data_size > (SIZE_MAX / sizeof(opj_v4_t))) {
/* FIXME event manager error callback */
+ opj_sparse_array_int32_free(sa);
return OPJ_FALSE;
}
h.wavelet = (opj_v4_t*) opj_aligned_malloc(l_data_size * sizeof(opj_v4_t));
if (!h.wavelet) {
/* FIXME event manager error callback */
+ opj_sparse_array_int32_free(sa);
return OPJ_FALSE;
}
v.wavelet = h.wavelet;