From: Even Rouault Date: Sat, 29 Jul 2017 15:28:55 +0000 (+0200) Subject: imagetopnm(): make sure the alpha component has same dimension as other components... X-Git-Tag: v2.2.0~36 X-Git-Url: https://main.carlh.net/gitweb/?p=openjpeg.git;a=commitdiff_plain;h=2fa0fc61f2d546c8b67e7c5a9cbc61d98e1f7af0 imagetopnm(): make sure the alpha component has same dimension as other components to avoid read heap buffer overflow (#970) --- diff --git a/src/bin/jp2/convert.c b/src/bin/jp2/convert.c index a540128f..730ab909 100644 --- a/src/bin/jp2/convert.c +++ b/src/bin/jp2/convert.c @@ -1890,6 +1890,21 @@ opj_image_t* pnmtoimage(const char *filename, opj_cparameters_t *parameters) return image; }/* pnmtoimage() */ +static int are_comps_similar(opj_image_t * image) +{ + unsigned int i; + for (i = 1; i < image->numcomps; i++) { + if (image->comps[0].dx != image->comps[i].dx || + image->comps[0].dy != image->comps[i].dy || + image->comps[0].prec != image->comps[i].prec || + image->comps[0].sgnd != image->comps[i].sgnd) { + return OPJ_FALSE; + } + } + return OPJ_TRUE; +} + + int imagetopnm(opj_image_t * image, const char *outfile, int force_split) { int *red, *green, *blue, *alpha; @@ -1926,15 +1941,7 @@ int imagetopnm(opj_image_t * image, const char *outfile, int force_split) } if ((force_split == 0) && - (ncomp == 2 /* GRAYA */ - || (ncomp > 2 /* RGB, RGBA */ - && image->comps[0].dx == image->comps[1].dx - && image->comps[1].dx == image->comps[2].dx - && image->comps[0].dy == image->comps[1].dy - && image->comps[1].dy == image->comps[2].dy - && image->comps[0].prec == image->comps[1].prec - && image->comps[1].prec == image->comps[2].prec - ))) { + are_comps_similar(image)) { fdest = fopen(outfile, "wb"); if (!fdest) {