From 161caf573ae659bb3715d934be59f3495ba31421 Mon Sep 17 00:00:00 2001 From: szukw000 Date: Thu, 18 Oct 2018 15:01:13 +0200 Subject: [PATCH] Change in imagetopnm of convert.c in case image->comps[].data is NULL --- src/bin/jp2/convert.c | 14 +++++++++++++- src/bin/jp2/opj_decompress.c | 21 +++++++++++++++++---- 2 files changed, 30 insertions(+), 5 deletions(-) diff --git a/src/bin/jp2/convert.c b/src/bin/jp2/convert.c index fa02e31c5..1607232d4 100644 --- a/src/bin/jp2/convert.c +++ b/src/bin/jp2/convert.c @@ -2021,7 +2021,7 @@ int imagetopnm(opj_image_t * image, const char *outfile, int force_split) int *red, *green, *blue, *alpha; int wr, hr, max; int i; - unsigned int compno, ncomp; + unsigned int compno, ncomp, ui; int adjustR, adjustG, adjustB, adjustA; int fails, two, want_gray, has_alpha, triple; int prec, v; @@ -2029,6 +2029,18 @@ int imagetopnm(opj_image_t * image, const char *outfile, int force_split) const char *tmp = outfile; char *destname; + fails = 0; + ncomp = image->numcomps; + for (ui = 0; ui < ncomp; ++ui) { + if (image->comps[ui].data == NULL) { + fprintf(stderr, "imagetopnm data[%u] == NULL\n", ui); + fails = 1; + } + } + if (fails) { + return 1; + } + alpha = NULL; if ((prec = (int)image->comps[0].prec) > 16) { diff --git a/src/bin/jp2/opj_decompress.c b/src/bin/jp2/opj_decompress.c index a28a194bb..8260ecba4 100644 --- a/src/bin/jp2/opj_decompress.c +++ b/src/bin/jp2/opj_decompress.c @@ -538,12 +538,25 @@ static int infile_format(const char *fname) return ext_format; } - s = fname + strlen(fname) - 4; + s = fname + strlen(fname) - 1; - fputs("\n===========================================\n", stderr); +#ifdef WIN32 + while (s > fname && (*s != '.' && *s != '\\')) { + --s; + } +#else + while (s > fname && (*s != '.' && *s != '/')) { + --s; + } +#endif + if (*s != '.') { + s = ""; + } + + fputs("\n===============================================\n", stderr); fprintf(stderr, "The extension of this file is incorrect.\n" - "FOUND %s. SHOULD BE %s\n", s, magic_s); - fputs("===========================================\n", stderr); + " FOUND '%s'. SHOULD BE '%s'", s, magic_s); + fputs("\n===============================================\n", stderr); return magic_format; }