summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/bin/jp2/convert.c46
-rw-r--r--src/lib/openjp2/j2k.c3
-rw-r--r--src/lib/openjp2/jp2.c2
3 files changed, 36 insertions, 15 deletions
diff --git a/src/bin/jp2/convert.c b/src/bin/jp2/convert.c
index 26af53f2..fa02e31c 100644
--- a/src/bin/jp2/convert.c
+++ b/src/bin/jp2/convert.c
@@ -1812,6 +1812,13 @@ opj_image_t* pnmtoimage(const char *filename, opj_cparameters_t *parameters)
return NULL;
}
+ if (header_info.width == 0
+ || header_info.height == 0
+ || (header_info.format == 7 && header_info.depth == 0)) {
+ fclose(fp);
+ return NULL;
+ }
+
/* This limitation could be removed by making sure to use size_t below */
if (header_info.height != 0 &&
header_info.width > INT_MAX / header_info.height) {
@@ -1897,8 +1904,10 @@ opj_image_t* pnmtoimage(const char *filename, opj_cparameters_t *parameters)
for (compno = 0; compno < numcomps; compno++) {
index = 0;
if (fscanf(fp, "%u", &index) != 1) {
- fprintf(stderr,
- "\nWARNING: fscanf return a number of element different from the expected.\n");
+ fprintf(stderr, "Missing data. Quitting.\n");
+ opj_image_destroy(image);
+ fclose(fp);
+ return NULL;
}
image->comps[compno].data[i] = (OPJ_INT32)(index * 255) / header_info.maxval;
@@ -1916,8 +1925,7 @@ opj_image_t* pnmtoimage(const char *filename, opj_cparameters_t *parameters)
for (i = 0; i < w * h; i++) {
for (compno = 0; compno < numcomps; compno++) {
if (!fread(&c0, 1, 1, fp)) {
- fprintf(stderr,
- "\nError: fread return a number of element different from the expected.\n");
+ fprintf(stderr, "Missing data. Quitting.\n");
opj_image_destroy(image);
fclose(fp);
return NULL;
@@ -1926,8 +1934,10 @@ opj_image_t* pnmtoimage(const char *filename, opj_cparameters_t *parameters)
image->comps[compno].data[i] = c0;
} else {
if (!fread(&c1, 1, 1, fp)) {
- fprintf(stderr,
- "\nError: fread return a number of element different from the expected.\n");
+ fprintf(stderr, "Missing data. Quitting.\n");
+ opj_image_destroy(image);
+ fclose(fp);
+ return NULL;
}
/* netpbm: */
image->comps[compno].data[i] = ((c0 << 8) | c1);
@@ -1939,15 +1949,17 @@ opj_image_t* pnmtoimage(const char *filename, opj_cparameters_t *parameters)
unsigned int index;
if (fscanf(fp, "%u", &index) != 1) {
- fprintf(stderr,
- "\nWARNING: fscanf return a number of element different from the expected.\n");
+ fprintf(stderr, "Missing data. Quitting.\n");
+ opj_image_destroy(image);
+ fclose(fp);
+ return NULL;
}
image->comps[0].data[i] = (index ? 0 : 255);
}
} else if (format == 4) {
int x, y, bit;
- unsigned char uc;
+ int uc;
i = 0;
for (y = 0; y < h; ++y) {
@@ -1957,9 +1969,15 @@ opj_image_t* pnmtoimage(const char *filename, opj_cparameters_t *parameters)
for (x = 0; x < w; ++x) {
if (bit == -1) {
bit = 7;
- uc = (unsigned char)getc(fp);
+ uc = getc(fp);
+ if (uc == EOF) {
+ fprintf(stderr, "Missing data. Quitting.\n");
+ opj_image_destroy(image);
+ fclose(fp);
+ return NULL;
+ }
}
- image->comps[0].data[i] = (((uc >> bit) & 1) ? 0 : 255);
+ image->comps[0].data[i] = ((((unsigned char)uc >> bit) & 1) ? 0 : 255);
--bit;
++i;
}
@@ -1969,8 +1987,10 @@ opj_image_t* pnmtoimage(const char *filename, opj_cparameters_t *parameters)
for (i = 0; i < w * h; ++i) {
if (!fread(&uc, 1, 1, fp)) {
- fprintf(stderr,
- "\nError: fread return a number of element different from the expected.\n");
+ fprintf(stderr, "Missing data. Quitting.\n");
+ opj_image_destroy(image);
+ fclose(fp);
+ return NULL;
}
image->comps[0].data[i] = (uc & 1) ? 0 : 255;
}
diff --git a/src/lib/openjp2/j2k.c b/src/lib/openjp2/j2k.c
index 28c7513f..4169cd67 100644
--- a/src/lib/openjp2/j2k.c
+++ b/src/lib/openjp2/j2k.c
@@ -1925,7 +1925,8 @@ static OPJ_BOOL opj_j2k_read_soc(opj_j2k_t *p_j2k,
/* FIXME move it in a index structure included in p_j2k*/
p_j2k->cstr_index->main_head_start = opj_stream_tell(p_stream) - 2;
- opj_event_msg(p_manager, EVT_INFO, "Start to read j2k main header (%d).\n",
+ opj_event_msg(p_manager, EVT_INFO,
+ "Start to read j2k main header (%" PRId64 ").\n",
p_j2k->cstr_index->main_head_start);
/* Add the marker to the codestream index*/
diff --git a/src/lib/openjp2/jp2.c b/src/lib/openjp2/jp2.c
index c79ea731..f15f45ae 100644
--- a/src/lib/openjp2/jp2.c
+++ b/src/lib/openjp2/jp2.c
@@ -1005,7 +1005,7 @@ static OPJ_BOOL opj_jp2_check_color(opj_image_t *image, opj_jp2_color_t *color,
if (!pcol_usage[i]) {
is_sane = 0U;
opj_event_msg(p_manager, EVT_WARNING,
- "Component mapping seems wrong. Trying to correct.\n", i);
+ "Component mapping seems wrong. Trying to correct.\n");
break;
}
}