summaryrefslogtreecommitdiff
path: root/src/bin/jp2/convert.c
diff options
context:
space:
mode:
authorszukw000 <szukw000@arcor.de>2017-07-31 13:58:08 +0200
committerszukw000 <szukw000@arcor.de>2017-07-31 13:58:08 +0200
commit00f45684a8339e69ed55df2397f3c19d09fecaed (patch)
tree171f881e7b3bcad1afed20d69aa7a8c02ec9dad8 /src/bin/jp2/convert.c
parent13cde9fa37249628af6b6f10601b733f87a025f4 (diff)
Catch images broken by AFL
Diffstat (limited to 'src/bin/jp2/convert.c')
-rw-r--r--src/bin/jp2/convert.c36
1 files changed, 32 insertions, 4 deletions
diff --git a/src/bin/jp2/convert.c b/src/bin/jp2/convert.c
index 492911c9..e2e16027 100644
--- a/src/bin/jp2/convert.c
+++ b/src/bin/jp2/convert.c
@@ -959,10 +959,11 @@ int imagetotga(opj_image_t * image, const char *outfile)
for (i = 0; i < image->numcomps - 1; i++) {
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)) {
+ || (image->comps[0].prec != image->comps[i + 1].prec)
+ || (image->comps[0].sgnd != image->comps[i + 1].sgnd)) {
fclose(fdest);
fprintf(stderr,
- "Unable to create a tga file with such J2K image charateristics.");
+ "Unable to create a tga file with such J2K image charateristics.\n");
return 1;
}
}
@@ -2343,7 +2344,7 @@ static int imagetoraw_common(opj_image_t * image, const char *outfile,
{
FILE *rawFile = NULL;
size_t res;
- unsigned int compno;
+ unsigned int compno, numcomps;
int w, h, fails;
int line, row, curr, mask;
int *ptr;
@@ -2355,6 +2356,33 @@ static int imagetoraw_common(opj_image_t * image, const char *outfile,
return 1;
}
+ numcomps = image->numcomps;
+
+ if (numcomps > 4) {
+ numcomps = 4;
+ }
+
+ for (compno = 1; compno < numcomps; ++compno) {
+ if (image->comps[0].dx != image->comps[compno].dx) {
+ break;
+ }
+ if (image->comps[0].dy != image->comps[compno].dy) {
+ break;
+ }
+ if (image->comps[0].prec != image->comps[compno].prec) {
+ break;
+ }
+ if (image->comps[0].sgnd != image->comps[compno].sgnd) {
+ break;
+ }
+ }
+ if (compno != numcomps) {
+ fprintf(stderr,
+ "imagetoraw_common: All components shall have the same subsampling, same bit depth, same sign.\n");
+ fprintf(stderr, "\tAborting\n");
+ return 1;
+ }
+
rawFile = fopen(outfile, "wb");
if (!rawFile) {
fprintf(stderr, "Failed to open %s for writing !!\n", outfile);
@@ -2466,7 +2494,7 @@ static int imagetoraw_common(opj_image_t * image, const char *outfile,
}
}
} else if (image->comps[compno].prec <= 32) {
- fprintf(stderr, "More than 16 bits per component no handled yet\n");
+ fprintf(stderr, "More than 16 bits per component not handled yet\n");
goto fin;
} else {
fprintf(stderr, "Error: invalid precision: %d\n", image->comps[compno].prec);