summaryrefslogtreecommitdiff
path: root/src/bin
diff options
context:
space:
mode:
authormayeut <mayeut@users.noreply.github.com>2015-10-06 20:55:36 +0200
committermayeut <mayeut@users.noreply.github.com>2015-10-06 20:55:36 +0200
commit2dab5fed591d19a3295b42225701801ee52569fb (patch)
treee70b732926ca0ac38b5cdc8e0d1cd0c49da7833d /src/bin
parent4bb5e24d234dbf239119524edae4e23f39de7ee4 (diff)
parente526d435cc874b97ae41eacc6b8b0b72419180fb (diff)
Merge branch 'master' into coc-qcc
Diffstat (limited to 'src/bin')
-rw-r--r--src/bin/common/opj_string.h72
-rw-r--r--src/bin/jp2/CMakeLists.txt1
-rw-r--r--src/bin/jp2/convert.c79
-rw-r--r--src/bin/jp2/convertbmp.c9
-rw-r--r--src/bin/jp2/convertpng.c2
-rw-r--r--src/bin/jp2/opj_compress.c52
-rw-r--r--src/bin/jp2/opj_decompress.c59
-rw-r--r--src/bin/jp2/opj_dump.c22
-rw-r--r--src/bin/jp2/windirent.h6
-rw-r--r--src/bin/jp3d/windirent.h6
-rw-r--r--src/bin/jpwl/convert.c2
-rw-r--r--src/bin/jpwl/opj_jpwl_compress.c2
-rw-r--r--src/bin/jpwl/windirent.h6
-rw-r--r--src/bin/mj2/meta_out.c4
-rw-r--r--src/bin/mj2/mj2_to_metadata.c2
-rw-r--r--src/bin/mj2/opj_mj2_wrap.c2
-rw-r--r--src/bin/wx/OPJViewer/source/readmebefore.txt2
17 files changed, 247 insertions, 81 deletions
diff --git a/src/bin/common/opj_string.h b/src/bin/common/opj_string.h
new file mode 100644
index 00000000..8829926a
--- /dev/null
+++ b/src/bin/common/opj_string.h
@@ -0,0 +1,72 @@
+/*
+ * The copyright in this software is being made available under the 2-clauses
+ * BSD License, included below. This software may be subject to other third
+ * party and contributor rights, including patent rights, and no such rights
+ * are granted under this license.
+ *
+ * Copyright (c) 2015, Matthieu Darbois
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef OPJ_STRING_H
+#define OPJ_STRING_H
+
+#include <errno.h>
+#include <string.h>
+
+/* strnlen is not standard, strlen_s is C11... */
+/* keep in mind there still is a buffer read overflow possible */
+static size_t opj_strnlen_s(const char *src, size_t max_len)
+{
+ size_t len;
+
+ if (src == NULL) {
+ return 0U;
+ }
+ for (len = 0U; (*src != '\0') && (len < max_len); src++, len++);
+ return len;
+}
+
+/* should be equivalent to C11 function except for the handler */
+/* keep in mind there still is a buffer read overflow possible */
+static int opj_strcpy_s(char* dst, size_t dst_size, const char* src)
+{
+ size_t src_len = 0U;
+ if ((dst == NULL) || (dst_size == 0U)) {
+ return EINVAL;
+ }
+ if (src == NULL) {
+ dst[0] = '\0';
+ return EINVAL;
+ }
+ src_len = opj_strnlen_s(src, dst_size);
+ if (src_len >= dst_size) {
+ return ERANGE;
+ }
+ memcpy(dst, src, src_len);
+ dst[src_len] = '\0';
+ return 0;
+}
+
+#endif /* OPJ_STRING_H */
diff --git a/src/bin/jp2/CMakeLists.txt b/src/bin/jp2/CMakeLists.txt
index 7e2476df..d583c2e6 100644
--- a/src/bin/jp2/CMakeLists.txt
+++ b/src/bin/jp2/CMakeLists.txt
@@ -11,6 +11,7 @@ set(common_SRCS
${OPENJPEG_SOURCE_DIR}/src/bin/common/color.h
${OPENJPEG_SOURCE_DIR}/src/bin/common/opj_getopt.c
${OPENJPEG_SOURCE_DIR}/src/bin/common/opj_getopt.h
+ ${OPENJPEG_SOURCE_DIR}/src/bin/common/opj_string.h
)
if(OPJ_HAVE_LIBTIFF)
diff --git a/src/bin/jp2/convert.c b/src/bin/jp2/convert.c
index a894a369..73ec9f6e 100644
--- a/src/bin/jp2/convert.c
+++ b/src/bin/jp2/convert.c
@@ -114,6 +114,7 @@ static void scale_component_up(opj_image_comp_t* component, OPJ_UINT32 precision
}
}
component->prec = precision;
+ component->bpp = precision;
}
void scale_component(opj_image_comp_t* component, OPJ_UINT32 precision)
{
@@ -573,7 +574,7 @@ static int tga_readheader(FILE *fp, unsigned int *bits_per_pixel,
unsigned int *width, unsigned int *height, int *flip_image)
{
int palette_size;
- unsigned char *tga ;
+ unsigned char tga[TGA_HEADER_SIZE];
unsigned char id_len, /*cmap_type,*/ image_type;
unsigned char pixel_depth, image_desc;
unsigned short /*cmap_index,*/ cmap_len, cmap_entry_size;
@@ -581,7 +582,6 @@ static int tga_readheader(FILE *fp, unsigned int *bits_per_pixel,
if (!bits_per_pixel || !width || !height || !flip_image)
return 0;
- tga = (unsigned char*)malloc(18);
if ( fread(tga, TGA_HEADER_SIZE, 1, fp) != 1 )
{
@@ -605,8 +605,6 @@ static int tga_readheader(FILE *fp, unsigned int *bits_per_pixel,
pixel_depth = (unsigned char)tga[16];
image_desc = (unsigned char)tga[17];
- free(tga);
-
*bits_per_pixel = (unsigned int)pixel_depth;
*width = (unsigned int)image_w;
*height = (unsigned int)image_h;
@@ -737,12 +735,16 @@ opj_image_t* tgatoimage(const char *filename, opj_cparameters_t *parameters) {
return 0;
}
- if (!tga_readheader(f, &pixel_bit_depth, &image_width, &image_height, &flip_image))
+ if (!tga_readheader(f, &pixel_bit_depth, &image_width, &image_height, &flip_image)) {
+ fclose(f);
return NULL;
+ }
/* We currently only support 24 & 32 bit tga's ... */
- if (!((pixel_bit_depth == 24) || (pixel_bit_depth == 32)))
+ if (!((pixel_bit_depth == 24) || (pixel_bit_depth == 32))) {
+ fclose(f);
return NULL;
+ }
/* initialize image components */
memset(&cmptparm[0], 0, 4 * sizeof(opj_image_cmptparm_t));
@@ -775,8 +777,11 @@ opj_image_t* tgatoimage(const char *filename, opj_cparameters_t *parameters) {
/* create the image */
image = opj_image_create((OPJ_UINT32)numcomps, &cmptparm[0], color_space);
- if (!image)
+ if (!image) {
+ fclose(f);
return NULL;
+ }
+
/* set image offset and reference grid */
image->x0 = (OPJ_UINT32)parameters->image_offset_x0;
@@ -804,18 +809,21 @@ opj_image_t* tgatoimage(const char *filename, opj_cparameters_t *parameters) {
{
fprintf(stderr, "\nError: fread return a number of element different from the expected.\n");
opj_image_destroy(image);
+ fclose(f);
return NULL;
}
if ( !fread(&g, 1, 1, f) )
{
fprintf(stderr, "\nError: fread return a number of element different from the expected.\n");
opj_image_destroy(image);
+ fclose(f);
return NULL;
}
if ( !fread(&r, 1, 1, f) )
{
fprintf(stderr, "\nError: fread return a number of element different from the expected.\n");
opj_image_destroy(image);
+ fclose(f);
return NULL;
}
@@ -834,24 +842,28 @@ opj_image_t* tgatoimage(const char *filename, opj_cparameters_t *parameters) {
{
fprintf(stderr, "\nError: fread return a number of element different from the expected.\n");
opj_image_destroy(image);
+ fclose(f);
return NULL;
}
if ( !fread(&g, 1, 1, f) )
{
fprintf(stderr, "\nError: fread return a number of element different from the expected.\n");
opj_image_destroy(image);
+ fclose(f);
return NULL;
}
if ( !fread(&r, 1, 1, f) )
{
fprintf(stderr, "\nError: fread return a number of element different from the expected.\n");
opj_image_destroy(image);
+ fclose(f);
return NULL;
}
if ( !fread(&a, 1, 1, f) )
{
fprintf(stderr, "\nError: fread return a number of element different from the expected.\n");
opj_image_destroy(image);
+ fclose(f);
return NULL;
}
@@ -866,6 +878,7 @@ opj_image_t* tgatoimage(const char *filename, opj_cparameters_t *parameters) {
fprintf(stderr, "Currently unsupported bit depth : %s\n", filename);
}
}
+ fclose(f);
return image;
}
@@ -892,6 +905,7 @@ int imagetotga(opj_image_t * image, const char *outfile) {
if ((image->comps[0].dx != image->comps[i+1].dx)
||(image->comps[0].dy != image->comps[i+1].dy)
||(image->comps[0].prec != image->comps[i+1].prec)) {
+ fclose(fdest);
fprintf(stderr, "Unable to create a tga file with such J2K image charateristics.");
return 1;
}
@@ -1084,6 +1098,7 @@ opj_image_t* pgxtoimage(const char *filename, opj_cparameters_t *parameters) {
fseek(f, 0, SEEK_SET);
if( fscanf(f, "PG%[ \t]%c%c%[ \t+-]%d%[ \t]%d%[ \t]%d",temp,&endian1,&endian2,signtmp,&prec,temp,&w,temp,&h) != 9){
+ fclose(f);
fprintf(stderr, "ERROR: Failed to read the right number of element from the fscanf() function!\n");
return NULL;
}
@@ -1101,6 +1116,7 @@ opj_image_t* pgxtoimage(const char *filename, opj_cparameters_t *parameters) {
} else if (endian2=='M' && endian1=='L') {
bigendian = 0;
} else {
+ fclose(f);
fprintf(stderr, "Bad pgx header, please check input file\n");
return NULL;
}
@@ -1215,7 +1231,7 @@ int imagetopgx(opj_image_t * image, const char *outfile)
FILE *fdest = NULL;
for (compno = 0; compno < image->numcomps; compno++)
- {
+ {
opj_image_comp_t *comp = &image->comps[compno];
char bname[256]; /* buffer for name */
char *name = bname; /* pointer */
@@ -1226,25 +1242,30 @@ int imagetopgx(opj_image_t * image, const char *outfile)
const size_t total = dotpos + 1 + 1 + 4; /* '-' + '[1-3]' + '.pgx' */
if( outfile[dotpos] != '.' )
- {
+ {
/* `pgx` was recognized but there is no dot at expected position */
fprintf(stderr, "ERROR -> Impossible happen." );
goto fin;
- }
+ }
if( total > 256 )
- {
+ {
name = (char*)malloc(total+1);
- }
+ if (name == NULL) {
+ goto fin;
+ }
+ }
strncpy(name, outfile, dotpos);
sprintf(name+dotpos, "_%d.pgx", compno);
fdest = fopen(name, "wb");
- /* dont need name anymore */
- if( total > 256 ) free(name);
+ /* don't need name anymore */
+
if (!fdest)
- {
+ {
+
fprintf(stderr, "ERROR -> failed to open %s for writing\n", name);
+ if( total > 256 ) free(name);
goto fin;
- }
+ }
w = (int)image->comps[compno].w;
h = (int)image->comps[compno].h;
@@ -1260,26 +1281,28 @@ int imagetopgx(opj_image_t * image, const char *outfile)
nbytes = 4;
for (i = 0; i < w * h; i++)
- {
+ {
/* FIXME: clamp func is being called within a loop */
const int val = clamp(image->comps[compno].data[i],
(int)comp->prec, (int)comp->sgnd);
for (j = nbytes - 1; j >= 0; j--)
- {
+ {
int v = (int)(val >> (j * 8));
unsigned char byte = (unsigned char)v;
res = fwrite(&byte, 1, 1, fdest);
if( res < 1 )
- {
+ {
fprintf(stderr, "failed to write 1 byte for %s\n", name);
+ if( total > 256 ) free(name);
goto fin;
- }
- }
- }
+ }
+ }
+ }
+ if( total > 256 ) free(name);
fclose(fdest); fdest = NULL;
- }
+ }
fails = 0;
fin:
if(fdest) fclose(fdest);
@@ -1653,6 +1676,7 @@ opj_image_t* pnmtoimage(const char *filename, opj_cparameters_t *parameters) {
{
fprintf(stderr, "\nError: fread return a number of element different from the expected.\n");
opj_image_destroy(image);
+ fclose(fp);
return NULL;
}
if(one)
@@ -2006,6 +2030,7 @@ static opj_image_t* rawtoimage_common(const char *filename, opj_cparameters_t *p
if (!cmptparm) {
fprintf(stderr, "Failed to allocate image components parameters !!\n");
fprintf(stderr,"Aborting\n");
+ fclose(f);
return NULL;
}
/* initialize image components */
@@ -2039,6 +2064,8 @@ static opj_image_t* rawtoimage_common(const char *filename, opj_cparameters_t *p
for (i = 0; i < nloop; i++) {
if (!fread(&value, 1, 1, f)) {
fprintf(stderr,"Error reading raw file. End of file probably reached.\n");
+ opj_image_destroy(image);
+ fclose(f);
return NULL;
}
image->comps[compno].data[i] = raw_cp->rawSigned?(char)value:value;
@@ -2055,10 +2082,14 @@ static opj_image_t* rawtoimage_common(const char *filename, opj_cparameters_t *p
unsigned char temp2;
if (!fread(&temp1, 1, 1, f)) {
fprintf(stderr,"Error reading raw file. End of file probably reached.\n");
+ opj_image_destroy(image);
+ fclose(f);
return NULL;
}
if (!fread(&temp2, 1, 1, f)) {
fprintf(stderr,"Error reading raw file. End of file probably reached.\n");
+ opj_image_destroy(image);
+ fclose(f);
return NULL;
}
if( big_endian )
@@ -2075,6 +2106,8 @@ static opj_image_t* rawtoimage_common(const char *filename, opj_cparameters_t *p
}
else {
fprintf(stderr,"OpenJPEG cannot encode raw components with bit depth higher than 16 bits.\n");
+ opj_image_destroy(image);
+ fclose(f);
return NULL;
}
diff --git a/src/bin/jp2/convertbmp.c b/src/bin/jp2/convertbmp.c
index 1131a599..910574b8 100644
--- a/src/bin/jp2/convertbmp.c
+++ b/src/bin/jp2/convertbmp.c
@@ -572,7 +572,7 @@ static OPJ_BOOL bmp_read_rle4_data(FILE* IN, OPJ_UINT8* pData, OPJ_UINT32 stride
OPJ_UINT8 c1 = (OPJ_UINT8)getc(IN);
for (j = 0; (j < c) && (x < width) && ((OPJ_SIZE_T)pix < (OPJ_SIZE_T)beyond); j++, x++, pix++) {
- *pix = (j&1) ? (c1 & 0x0f) : ((c1>>4)&0x0f);
+ *pix = (OPJ_UINT8)((j&1) ? (c1 & 0x0fU) : ((c1>>4)&0x0fU));
}
}
else { /* absolute mode */
@@ -598,7 +598,7 @@ static OPJ_BOOL bmp_read_rle4_data(FILE* IN, OPJ_UINT8* pData, OPJ_UINT32 stride
if((j&1) == 0) {
c1 = (OPJ_UINT8)getc(IN);
}
- *pix = (j&1) ? (c1 & 0x0f) : ((c1>>4)&0x0f);
+ *pix = (OPJ_UINT8)((j&1) ? (c1 & 0x0fU) : ((c1>>4)&0x0fU));
}
if(((c&3) == 1) || ((c&3) == 2)) { /* skip padding byte */
getc(IN);
@@ -729,6 +729,7 @@ opj_image_t* bmptoimage(const char *filename, opj_cparameters_t *parameters)
image = opj_image_create(numcmpts, &cmptparm[0], (numcmpts == 1U) ? OPJ_CLRSPC_GRAY : OPJ_CLRSPC_SRGB);
if(!image) {
fclose(IN);
+ free(pData);
return NULL;
}
if (numcmpts == 4U) {
@@ -902,6 +903,10 @@ int imagetobmp(opj_image_t * image, const char *outfile) {
<<-- <<-- <<-- <<-- */
fdest = fopen(outfile, "wb");
+ if (!fdest) {
+ fprintf(stderr, "ERROR -> failed to open %s for writing\n", outfile);
+ return 1;
+ }
w = (int)image->comps[0].w;
h = (int)image->comps[0].h;
diff --git a/src/bin/jp2/convertpng.c b/src/bin/jp2/convertpng.c
index 5a72d9fe..0999edbf 100644
--- a/src/bin/jp2/convertpng.c
+++ b/src/bin/jp2/convertpng.c
@@ -486,7 +486,7 @@ fin:
}
fclose(writer);
- if(fails) remove(write_idf);
+ if(fails) (void)remove(write_idf); /* ignore return value */
return fails;
}/* imagetopng() */
diff --git a/src/bin/jp2/opj_compress.c b/src/bin/jp2/opj_compress.c
index ee473ce3..9d690a56 100644
--- a/src/bin/jp2/opj_compress.c
+++ b/src/bin/jp2/opj_compress.c
@@ -69,6 +69,7 @@
#include "index.h"
#include "format_defs.h"
+#include "opj_string.h"
typedef struct dircnt{
/** Buffer for holding images read from Directory*/
@@ -391,6 +392,7 @@ static unsigned int get_num_images(char *imgdirpath){
continue;
num_images++;
}
+ closedir(dir);
return num_images;
}
@@ -416,6 +418,7 @@ static int load_images(dircnt_t *dirptr, char *imgdirpath){
strcpy(dirptr->filename[i],content->d_name);
i++;
}
+ closedir(dir);
return 0;
}
@@ -454,8 +457,10 @@ static char get_next_file(int imageno,dircnt_t *dirptr,img_fol_t *img_fol, opj_c
if (parameters->decod_format == -1)
return 1;
sprintf(infilename,"%s/%s",img_fol->imgdirpath,image_filename);
- strncpy(parameters->infile, infilename, sizeof(infilename));
-
+ if (opj_strcpy_s(parameters->infile, sizeof(parameters->infile), infilename) != 0) {
+ return 1;
+ }
+
/*Set output file*/
strcpy(temp_ofname,get_file_name(image_filename));
while((temp_p = strtok(NULL,".")) != NULL){
@@ -464,7 +469,9 @@ static char get_next_file(int imageno,dircnt_t *dirptr,img_fol_t *img_fol, opj_c
}
if(img_fol->set_out_format==1){
sprintf(outfilename,"%s/%s.%s",img_fol->imgdirpath,temp_ofname,img_fol->out_format);
- strncpy(parameters->outfile, outfilename, sizeof(outfilename));
+ if (opj_strcpy_s(parameters->outfile, sizeof(parameters->outfile), outfilename) != 0) {
+ return 1;
+ }
}
return 0;
}
@@ -472,7 +479,7 @@ static char get_next_file(int imageno,dircnt_t *dirptr,img_fol_t *img_fol, opj_c
/* ------------------------------------------------------------------------------------ */
static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *parameters,
- img_fol_t *img_fol, raw_cparameters_t *raw_cp, char *indexfilename) {
+ img_fol_t *img_fol, raw_cparameters_t *raw_cp, char *indexfilename, size_t indexfilename_size) {
OPJ_UINT32 i, j;
int totlen, c;
opj_option_t long_option[]={
@@ -526,7 +533,9 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
infile);
return 1;
}
- strncpy(parameters->infile, infile, sizeof(parameters->infile)-1);
+ if (opj_strcpy_s(parameters->infile, sizeof(parameters->infile), infile) != 0) {
+ return 1;
+ }
}
break;
@@ -544,7 +553,9 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
fprintf(stderr, "Unknown output format image %s [only *.j2k, *.j2c or *.jp2]!! \n", outfile);
return 1;
}
- strncpy(parameters->outfile, outfile, sizeof(parameters->outfile)-1);
+ if (opj_strcpy_s(parameters->outfile, sizeof(parameters->outfile), outfile) != 0) {
+ return 1;
+ }
}
break;
@@ -610,6 +621,9 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
substr2++; /* skip '@' character */
}
substr1 = (char*) malloc((len+1)*sizeof(char));
+ if (substr1 == NULL) {
+ return 1;
+ }
memcpy(substr1,opj_optarg,len);
substr1[len] = '\0';
if (sscanf(substr1, "%d,%d,%d,%d,%c", &width, &height, &ncomp, &bitdepth, &signo) == 5) {
@@ -661,7 +675,7 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
}
}
}
- if (substr1) free(substr1);
+ free(substr1);
if (wrong) {
fprintf(stderr,"\nError: invalid raw image parameters\n");
fprintf(stderr,"Please use the Format option -F:\n");
@@ -807,8 +821,9 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
case 'x': /* creation of index file */
{
- char *index = opj_optarg;
- strncpy(indexfilename, index, OPJ_PATH_LEN);
+ if (opj_strcpy_s(indexfilename, indexfilename_size, opj_optarg) != 0) {
+ return 1;
+ }
/* FIXME ADE INDEX >> */
fprintf(stderr,
"[WARNING] Index file generation is currently broken.\n"
@@ -1058,9 +1073,16 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
lStrLen = (size_t)ftell(lFile);
fseek(lFile,0,SEEK_SET);
lMatrix = (char *) malloc(lStrLen + 1);
+ if (lMatrix == NULL) {
+ fclose(lFile);
+ return 1;
+ }
lStrFread = fread(lMatrix, 1, lStrLen, lFile);
fclose(lFile);
- if( lStrLen != lStrFread ) return 1;
+ if( lStrLen != lStrFread ) {
+ free(lMatrix);
+ return 1;
+ }
lMatrix[lStrLen] = 0;
lCurrentPtr = lMatrix;
@@ -1080,6 +1102,10 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
lMctComp = lNbComp * lNbComp;
lTotalComp = lMctComp + lNbComp;
lSpace = (float *) malloc((size_t)lTotalComp * sizeof(float));
+ if(lSpace == NULL) {
+ free(lMatrix);
+ return 1;
+ }
lCurrentDoublePtr = lSpace;
for (i2=0;i2<lMctComp;++i2) {
lStrLen = strlen(lCurrentPtr) + 1;
@@ -1117,7 +1143,9 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param
/* we need to enable indexing */
if (!indexfilename || !*indexfilename) {
- strncpy(indexfilename, JPWL_PRIVATEINDEX_NAME, OPJ_PATH_LEN);
+ if (opj_strcpy_s(indexfilename, indexfilename_size, JPWL_PRIVATEINDEX_NAME) != 0) {
+ return 1;
+ }
}
/* search for different protection methods */
@@ -1606,7 +1634,7 @@ int main(int argc, char **argv) {
/* parse input and get user encoding parameters */
parameters.tcp_mct = (char) 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) == 1) {
+ if(parse_cmdline_encoder(argc, argv, &parameters,&img_fol, &raw_cp, indexfilename, sizeof(indexfilename)) == 1) {
return 1;
}
diff --git a/src/bin/jp2/opj_decompress.c b/src/bin/jp2/opj_decompress.c
index da566ac2..04803e0e 100644
--- a/src/bin/jp2/opj_decompress.c
+++ b/src/bin/jp2/opj_decompress.c
@@ -75,6 +75,7 @@
#include "color.h"
#include "format_defs.h"
+#include "opj_string.h"
typedef struct dircnt{
/** Buffer for holding images read from Directory*/
@@ -121,6 +122,8 @@ typedef struct opj_decompress_params
int decod_format;
/** output file format 0: PGX, 1: PxM, 2: BMP */
int cod_format;
+ /** index file name */
+ char indexfilename[OPJ_PATH_LEN];
/** Decoding area left boundary */
OPJ_UINT32 DA_x0;
@@ -157,7 +160,7 @@ int get_file_format(const char *filename);
char get_next_file(int imageno,dircnt_t *dirptr,img_fol_t *img_fol, opj_decompress_parameters *parameters);
static int infile_format(const char *fname);
-int parse_cmdline_decoder(int argc, char **argv, opj_decompress_parameters *parameters,img_fol_t *img_fol, char *indexfilename);
+int parse_cmdline_decoder(int argc, char **argv, opj_decompress_parameters *parameters,img_fol_t *img_fol);
int parse_DA_values( char* inArg, unsigned int *DA_x0, unsigned int *DA_y0, unsigned int *DA_x1, unsigned int *DA_y1);
static opj_image_t* convert_gray_to_rgb(opj_image_t* original);
@@ -361,6 +364,7 @@ int get_num_images(char *imgdirpath){
continue;
num_images++;
}
+ closedir(dir);
return num_images;
}
@@ -387,6 +391,7 @@ int load_images(dircnt_t *dirptr, char *imgdirpath){
strcpy(dirptr->filename[i],content->d_name);
i++;
}
+ closedir(dir);
return 0;
}
@@ -427,7 +432,9 @@ char get_next_file(int imageno,dircnt_t *dirptr,img_fol_t *img_fol, opj_decompre
parameters->decod_format = infile_format(infilename);
if (parameters->decod_format == -1)
return 1;
- strncpy(parameters->infile, infilename, sizeof(infilename));
+ if (opj_strcpy_s(parameters->infile, sizeof(parameters->infile), infilename) != 0) {
+ return 1;
+ }
/*Set output file*/
strcpy(temp_ofname,strtok(image_filename,"."));
@@ -437,7 +444,9 @@ char get_next_file(int imageno,dircnt_t *dirptr,img_fol_t *img_fol, opj_decompre
}
if(img_fol->set_out_format==1){
sprintf(outfilename,"%s/%s.%s",img_fol->imgdirpath,temp_ofname,img_fol->out_format);
- strncpy(parameters->outfile, outfilename, sizeof(outfilename));
+ if (opj_strcpy_s(parameters->outfile, sizeof(parameters->outfile), outfilename) != 0) {
+ return 1;
+ }
}
return 0;
}
@@ -503,7 +512,7 @@ static int infile_format(const char *fname)
* Parse the command line
*/
/* -------------------------------------------------------------------------- */
-int parse_cmdline_decoder(int argc, char **argv, opj_decompress_parameters *parameters,img_fol_t *img_fol, char *indexfilename) {
+int parse_cmdline_decoder(int argc, char **argv, opj_decompress_parameters *parameters,img_fol_t *img_fol) {
/* parse the command line */
int totlen, c;
opj_option_t long_option[]={
@@ -559,7 +568,10 @@ int parse_cmdline_decoder(int argc, char **argv, opj_decompress_parameters *para
infile);
return 1;
}
- strncpy(parameters->infile, infile, sizeof(parameters->infile)-1);
+ if (opj_strcpy_s(parameters->infile, sizeof(parameters->infile), infile) != 0) {
+ fprintf(stderr, "[ERROR] Path is too long\n");
+ return 1;
+ }
}
break;
@@ -590,7 +602,10 @@ int parse_cmdline_decoder(int argc, char **argv, opj_decompress_parameters *para
fprintf(stderr, "Unknown output format image %s [only *.pnm, *.pgm, *.ppm, *.pgx, *.bmp, *.tif, *.raw or *.tga]!! \n", outfile);
return 1;
}
- strncpy(parameters->outfile, outfile, sizeof(parameters->outfile)-1);
+ if (opj_strcpy_s(parameters->outfile, sizeof(parameters->outfile), outfile) != 0) {
+ fprintf(stderr, "[ERROR] Path is too long\n");
+ return 1;
+ }
}
break;
@@ -674,11 +689,14 @@ int parse_cmdline_decoder(int argc, char **argv, opj_decompress_parameters *para
case 'd': /* Input decode ROI */
{
- int size_optarg = (int)strlen(opj_optarg) + 1;
- char *ROI_values = (char*) malloc((size_t)size_optarg);
+ size_t size_optarg = (size_t)strlen(opj_optarg) + 1U;
+ char *ROI_values = (char*) malloc(size_optarg);
+ if (ROI_values == NULL) {
+ fprintf(stderr, "[ERROR] Couldn't allocate memory\n");
+ return 1;
+ }
ROI_values[0] = '\0';
- strncpy(ROI_values, opj_optarg, strlen(opj_optarg));
- ROI_values[strlen(opj_optarg)] = '\0';
+ memcpy(ROI_values, opj_optarg, size_optarg);
/*printf("ROI_values = %s [%d / %d]\n", ROI_values, strlen(ROI_values), size_optarg ); */
parse_DA_values( ROI_values, &parameters->DA_x0, &parameters->DA_y0, &parameters->DA_x1, &parameters->DA_y1);
@@ -699,8 +717,10 @@ int parse_cmdline_decoder(int argc, char **argv, opj_decompress_parameters *para
case 'x': /* Creation of index file */
{
- char *index = opj_optarg;
- strncpy(indexfilename, index, OPJ_PATH_LEN);
+ if (opj_strcpy_s(parameters->indexfilename, sizeof(parameters->indexfilename), opj_optarg) != 0) {
+ fprintf(stderr, "[ERROR] Path is too long\n");
+ return 1;
+ }
}
break;
@@ -1088,7 +1108,7 @@ static opj_image_t* upsample_image_components(opj_image_t* original)
l_dst += l_new_cmp->w;
}
- if(l_new_cmp->h > (l_org_cmp->dy - 1U)) { /* check substraction overflow for really small images */
+ if(l_new_cmp->h > (l_org_cmp->dy - 1U)) { /* check subtraction overflow for really small images */
for (; y < l_new_cmp->h - (l_org_cmp->dy - 1U); y += l_org_cmp->dy) {
OPJ_UINT32 x, dy;
OPJ_UINT32 xorg;
@@ -1097,7 +1117,7 @@ static opj_image_t* upsample_image_components(opj_image_t* original)
for (x = 0U; x < xoff; ++x) {
l_dst[x] = 0;
}
- if (l_new_cmp->w > (l_org_cmp->dx - 1U)) { /* check substraction overflow for really small images */
+ if (l_new_cmp->w > (l_org_cmp->dx - 1U)) { /* check subtraction overflow for really small images */
for (; x < l_new_cmp->w - (l_org_cmp->dx - 1U); x += l_org_cmp->dx, ++xorg) {
OPJ_UINT32 dx;
for (dx = 0U; dx < l_org_cmp->dx; ++dx) {
@@ -1125,7 +1145,7 @@ static opj_image_t* upsample_image_components(opj_image_t* original)
for (x = 0U; x < xoff; ++x) {
l_dst[x] = 0;
}
- if (l_new_cmp->w > (l_org_cmp->dx - 1U)) { /* check substraction overflow for really small images */
+ if (l_new_cmp->w > (l_org_cmp->dx - 1U)) { /* check subtraction overflow for really small images */
for (; x < l_new_cmp->w - (l_org_cmp->dx - 1U); x += l_org_cmp->dx, ++xorg) {
OPJ_UINT32 dx;
for (dx = 0U; dx < l_org_cmp->dx; ++dx) {
@@ -1165,8 +1185,6 @@ int main(int argc, char **argv)
opj_codec_t* l_codec = NULL; /* Handle to a decompressor */
opj_codestream_index_t* cstr_index = NULL;
- char indexfilename[OPJ_PATH_LEN]; /* index file name */
-
OPJ_INT32 num_images, imageno;
img_fol_t img_fol;
dircnt_t *dirptr = NULL;
@@ -1177,14 +1195,11 @@ int main(int argc, char **argv)
/* set decoding parameters to default values */
set_default_parameters(&parameters);
- /* FIXME Initialize indexfilename and img_fol */
- *indexfilename = 0;
-
/* Initialize img_fol */
memset(&img_fol,0,sizeof(img_fol_t));
/* parse input and get user encoding parameters */
- if(parse_cmdline_decoder(argc, argv, &parameters,&img_fol, indexfilename) == 1) {
+ if(parse_cmdline_decoder(argc, argv, &parameters,&img_fol) == 1) {
destroy_parameters(&parameters);
return EXIT_FAILURE;
}
@@ -1550,7 +1565,7 @@ int main(int argc, char **argv)
/* destroy the codestream index */
opj_destroy_cstr_index(&cstr_index);
- if(failed) remove(parameters.outfile);
+ if(failed) (void)remove(parameters.outfile); /* ignore return value */
}
destroy_parameters(&parameters);
if (numDecompressedImages) {
diff --git a/src/bin/jp2/opj_dump.c b/src/bin/jp2/opj_dump.c
index a85cfe90..562fd5a5 100644
--- a/src/bin/jp2/opj_dump.c
+++ b/src/bin/jp2/opj_dump.c
@@ -57,6 +57,7 @@
#include "index.h"
#include "format_defs.h"
+#include "opj_string.h"
typedef struct dircnt{
/** Buffer for holding images read from Directory*/
@@ -134,6 +135,7 @@ static int get_num_images(char *imgdirpath){
continue;
num_images++;
}
+ closedir(dir);
return num_images;
}
@@ -160,6 +162,7 @@ static int load_images(dircnt_t *dirptr, char *imgdirpath){
strcpy(dirptr->filename[i],content->d_name);
i++;
}
+ closedir(dir);
return 0;
}
@@ -194,7 +197,9 @@ static char get_next_file(int imageno,dircnt_t *dirptr,img_fol_t *img_fol, opj_d
if (parameters->decod_format == -1)
return 1;
sprintf(infilename,"%s/%s",img_fol->imgdirpath,image_filename);
- strncpy(parameters->infile, infilename, sizeof(infilename));
+ if (opj_strcpy_s(parameters->infile, sizeof(parameters->infile), infilename) != 0) {
+ return 1;
+ }
/*Set output file*/
strcpy(temp_ofname,strtok(image_filename,"."));
@@ -204,7 +209,9 @@ static char get_next_file(int imageno,dircnt_t *dirptr,img_fol_t *img_fol, opj_d
}
if(img_fol->set_out_format==1){
sprintf(outfilename,"%s/%s.%s",img_fol->imgdirpath,temp_ofname,img_fol->out_format);
- strncpy(parameters->outfile, outfilename, sizeof(outfilename));
+ if (opj_strcpy_s(parameters->outfile, sizeof(parameters->outfile), outfilename) != 0) {
+ return 1;
+ }
}
return 0;
}
@@ -301,7 +308,10 @@ static int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *param
infile);
return 1;
}
- strncpy(parameters->infile, infile, sizeof(parameters->infile)-1);
+ if (opj_strcpy_s(parameters->infile, sizeof(parameters->infile), infile) != 0) {
+ fprintf(stderr, "[ERROR] Path is too long\n");
+ return 1;
+ }
}
break;
@@ -309,8 +319,10 @@ static int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *param
case 'o': /* output file */
{
- char *outfile = opj_optarg;
- strncpy(parameters->outfile, outfile, sizeof(parameters->outfile)-1);
+ if (opj_strcpy_s(parameters->outfile, sizeof(parameters->outfile), opj_optarg) != 0) {
+ fprintf(stderr, "[ERROR] Path is too long\n");
+ return 1;
+ }
}
break;
diff --git a/src/bin/jp2/windirent.h b/src/bin/jp2/windirent.h
index 944b7d71..bef28194 100644
--- a/src/bin/jp2/windirent.h
+++ b/src/bin/jp2/windirent.h
@@ -243,7 +243,7 @@
* Substitute for real dirent structure. Note that `d_name' field is a
* true character array although we have it copied in the implementation
* dependent data. We could save some memory if we had declared `d_name'
- * as a pointer refering the name within implementation dependent data.
+ * as a pointer referring the name within implementation dependent data.
* We have not done that since some code may rely on sizeof(d_name) to be
* something other than four. Besides, directory entries are typically so
* small that it takes virtually no time to copy them from place to place.
@@ -411,7 +411,7 @@ static DIR *opendir(const char *dirname)
* capacity of d_name with different macros and some systems do not define
* capacity at all (besides actual declaration of the field). If you really
* need to find out storage capacity of d_name then you might want to try
- * NAME_MAX macro. The NAME_MAX is defined in POSIX standard althought
+ * NAME_MAX macro. The NAME_MAX is defined in POSIX standard although
* there are many MS-DOS and MS-Windows implementations those do not define
* it. There are also systems that declare d_name as "char d_name[1]" and
* then allocate suitable amount of memory at run-time. Thanks to Alain
@@ -466,7 +466,7 @@ readdir (DIR *dirp)
/* fill in entry and return that */
#if defined(DIRENT_WIN32_INTERFACE)
if (FindNextFile (dirp->search_handle, &dirp->current.data) == FALSE) {
- /* Last file has been processed or an error occured */
+ /* Last file has been processed or an error occurred */
FindClose (dirp->search_handle);
dirp->search_handle = INVALID_HANDLE_VALUE;
errno = ENOENT;
diff --git a/src/bin/jp3d/windirent.h b/src/bin/jp3d/windirent.h
index 72b38cea..2494cd4e 100644
--- a/src/bin/jp3d/windirent.h
+++ b/src/bin/jp3d/windirent.h
@@ -242,7 +242,7 @@
* Substitute for real dirent structure. Note that `d_name' field is a
* true character array although we have it copied in the implementation
* dependent data. We could save some memory if we had declared `d_name'
- * as a pointer refering the name within implementation dependent data.
+ * as a pointer referring the name within implementation dependent data.
* We have not done that since some code may rely on sizeof(d_name) to be
* something other than four. Besides, directory entries are typically so
* small that it takes virtually no time to copy them from place to place.
@@ -410,7 +410,7 @@ static DIR *opendir(const char *dirname)
* capacity of d_name with different macros and some systems do not define
* capacity at all (besides actual declaration of the field). If you really
* need to find out storage capacity of d_name then you might want to try
- * NAME_MAX macro. The NAME_MAX is defined in POSIX standard althought
+ * NAME_MAX macro. The NAME_MAX is defined in POSIX standard although
* there are many MS-DOS and MS-Windows implementations those do not define
* it. There are also systems that declare d_name as "char d_name[1]" and
* then allocate suitable amount of memory at run-time. Thanks to Alain
@@ -465,7 +465,7 @@ readdir (DIR *dirp)
/* fill in entry and return that */
#if defined(DIRENT_WIN32_INTERFACE)
if (FindNextFile (dirp->search_handle, &dirp->current.data) == FALSE) {
- /* Last file has been processed or an error occured */
+ /* Last file has been processed or an error occurred */
FindClose (dirp->search_handle);
dirp->search_handle = INVALID_HANDLE_VALUE;
errno = ENOENT;
diff --git a/src/bin/jpwl/convert.c b/src/bin/jpwl/convert.c
index de04e22f..bf7b5641 100644
--- a/src/bin/jpwl/convert.c
+++ b/src/bin/jpwl/convert.c
@@ -1436,7 +1436,7 @@ int imagetopgx(opj_image_t * image, const char *outfile) {
fprintf(stderr, "ERROR -> failed to open %s for writing\n", name);
return 1;
}
- /* dont need name anymore */
+ /* don't need name anymore */
if( total > 256 ) {
free(name);
}
diff --git a/src/bin/jpwl/opj_jpwl_compress.c b/src/bin/jpwl/opj_jpwl_compress.c
index 7537b61d..7410486e 100644
--- a/src/bin/jpwl/opj_jpwl_compress.c
+++ b/src/bin/jpwl/opj_jpwl_compress.c
@@ -199,7 +199,7 @@ static void encode_help_display(void) {
fprintf(stdout," Indicate multiple modes by adding their values. \n");
fprintf(stdout," ex: RESTART(4) + RESET(2) + SEGMARK(32) = -M 38\n");
fprintf(stdout,"\n");
- fprintf(stdout,"-TP : devide packets of every tile into tile-parts (-TP R) [R, L, C]\n");
+ fprintf(stdout,"-TP : divide packets of every tile into tile-parts (-TP R) [R, L, C]\n");
fprintf(stdout,"\n");
fprintf(stdout,"-x : create an index file *.Idx (-x index_name.Idx) \n");
fprintf(stdout,"\n");
diff --git a/src/bin/jpwl/windirent.h b/src/bin/jpwl/windirent.h
index 944b7d71..bef28194 100644
--- a/src/bin/jpwl/windirent.h
+++ b/src/bin/jpwl/windirent.h
@@ -243,7 +243,7 @@
* Substitute for real dirent structure. Note that `d_name' field is a
* true character array although we have it copied in the implementation
* dependent data. We could save some memory if we had declared `d_name'
- * as a pointer refering the name within implementation dependent data.
+ * as a pointer referring the name within implementation dependent data.
* We have not done that since some code may rely on sizeof(d_name) to be
* something other than four. Besides, directory entries are typically so
* small that it takes virtually no time to copy them from place to place.
@@ -411,7 +411,7 @@ static DIR *opendir(const char *dirname)
* capacity of d_name with different macros and some systems do not define
* capacity at all (besides actual declaration of the field). If you really
* need to find out storage capacity of d_name then you might want to try
- * NAME_MAX macro. The NAME_MAX is defined in POSIX standard althought
+ * NAME_MAX macro. The NAME_MAX is defined in POSIX standard although
* there are many MS-DOS and MS-Windows implementations those do not define
* it. There are also systems that declare d_name as "char d_name[1]" and
* then allocate suitable amount of memory at run-time. Thanks to Alain
@@ -466,7 +466,7 @@ readdir (DIR *dirp)
/* fill in entry and return that */
#if defined(DIRENT_WIN32_INTERFACE)
if (FindNextFile (dirp->search_handle, &dirp->current.data) == FALSE) {
- /* Last file has been processed or an error occured */
+ /* Last file has been processed or an error occurred */
FindClose (dirp->search_handle);
dirp->search_handle = INVALID_HANDLE_VALUE;
errno = ENOENT;
diff --git a/src/bin/mj2/meta_out.c b/src/bin/mj2/meta_out.c
index b6795045..f5ca0be8 100644
--- a/src/bin/mj2/meta_out.c
+++ b/src/bin/mj2/meta_out.c
@@ -375,7 +375,7 @@ void xml_write_free_and_skip(FILE* xmlout, opj_mj2_t * movie) {
}
void xml_write_uuid(FILE* xmlout, opj_mj2_t * movie) {
-/* Univeral Unique IDs of 16 bytes. */
+/* Universal Unique IDs of 16 bytes. */
#ifdef NOTYET
/* NO-OP so far. There can be zero or more instances of private uuid boxes in a file.
This function supports the top level of the file, but uuid may be elsewhere [not yet supported].
@@ -962,7 +962,7 @@ int xml_out_frame(FILE* file, FILE* xmlout, mj2_sample_t *sample, unsigned int s
fprintf(xmlout, " <JP2_Frame Num=\"%d\">\n", snum+1);
fprintf(xmlout, " <MainHeader>\n");
/* There can be multiple codestreams; a particular image is entirely within a single codestream */
- /* TO DO: A frame can be represented by two I-guess-contigious codestreams if its interleaved. */
+ /* TO DO: A frame can be represented by two I-guess-contiguous codestreams if its interleaved. */
fprintf(xmlout, " <StartOfCodestream Marker=\"SOC\" />\n");
/* "cp" stands for "coding parameter"; "tcp" is tile coding parameters, "tccp" is tile-component coding parameters */
xml_out_frame_siz(xmlout, img, cp); /* reqd in main */
diff --git a/src/bin/mj2/mj2_to_metadata.c b/src/bin/mj2/mj2_to_metadata.c
index 489f19cb..2ec2829d 100644
--- a/src/bin/mj2/mj2_to_metadata.c
+++ b/src/bin/mj2/mj2_to_metadata.c
@@ -64,7 +64,7 @@ void help_display()
fprintf(stdout,"----------\n");
fprintf(stdout,"The metadata includes the jp2 image and tile headers of the first frame.\n");
fprintf(stdout,"\n");
- fprintf(stdout,"Metadata values are shown in 'raw' form (e.g., hexidecimal) as stored in the\n");
+ fprintf(stdout,"Metadata values are shown in 'raw' form (e.g., hexadecimal) as stored in the\n");
fprintf(stdout,"file, and, if apt, in a 'derived' form that is more quickly grasped.\n");
fprintf(stdout,"\n");
fprintf(stdout,"Notes explaining the XML are embedded as terse comments. These include\n");
diff --git a/src/bin/mj2/opj_mj2_wrap.c b/src/bin/mj2/opj_mj2_wrap.c
index 7daa147f..59fb871d 100644
--- a/src/bin/mj2/opj_mj2_wrap.c
+++ b/src/bin/mj2/opj_mj2_wrap.c
@@ -356,7 +356,7 @@ static void setparams(opj_mj2_t *movie, opj_image_t *image) {
movie->tk[0].jp2_struct.enumcs = 18; /* YUV */
else
- movie->tk[0].jp2_struct.enumcs = 0; /* Unkown profile */
+ movie->tk[0].jp2_struct.enumcs = 0; /* Unknown profile */
}
int main(int argc, char *argv[]) {
diff --git a/src/bin/wx/OPJViewer/source/readmebefore.txt b/src/bin/wx/OPJViewer/source/readmebefore.txt
index a59b0e87..c945d291 100644
--- a/src/bin/wx/OPJViewer/source/readmebefore.txt
+++ b/src/bin/wx/OPJViewer/source/readmebefore.txt
@@ -8,4 +8,4 @@ Anybody. As the OpenJPEG library is released under the BSD license, anybody can
Who is developing the library ?
===============================
-The library is developed by the Communications and Remote Sensing Lab (TELE), in the Université Catholique de Louvain (UCL). The JPWL module is developped and maintained by the Digital Signal Processing Lab (DSPLab) of the University of Perugia, Italy (UNIPG). As our purpose is to make OpenJPEG really useful for those interested in the image compression field, any feedback/advices are obviously welcome ! We will do our best to handle them quickly. \ No newline at end of file
+The library is developed by the Communications and Remote Sensing Lab (TELE), in the Université Catholique de Louvain (UCL). The JPWL module is developed and maintained by the Digital Signal Processing Lab (DSPLab) of the University of Perugia, Italy (UNIPG). As our purpose is to make OpenJPEG really useful for those interested in the image compression field, any feedback/advices are obviously welcome ! We will do our best to handle them quickly.