diff options
| author | Even Rouault <even.rouault@spatialys.com> | 2020-04-01 20:58:55 +0200 |
|---|---|---|
| committer | Even Rouault <even.rouault@spatialys.com> | 2020-04-01 21:11:36 +0200 |
| commit | 1c54024165fd5db0e6047f28903274eb27d0980f (patch) | |
| tree | 86ce2c02bf2cc2f11cab5bd7130a66d4ce34381c /src/bin/jp2/convert.c | |
| parent | 563ecfb55ca77c0fc5ea19e4885e00f55ec82ca9 (diff) | |
opj_decompress: add sanity checks to avoid segfault in case of decoding error
Prevent crashes like:
opj_decompress -i 0722_5-1_2019.jp2 -o out.ppm -r 4 -t 0
where 0722_5-1_2019.jp2 is
https://drive.google.com/file/d/1ZxOUZg2-FKjYwa257VFLMpTXRWxEoP0a/view?usp=sharing
Diffstat (limited to 'src/bin/jp2/convert.c')
| -rw-r--r-- | src/bin/jp2/convert.c | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/src/bin/jp2/convert.c b/src/bin/jp2/convert.c index e670cd82..23f820c0 100644 --- a/src/bin/jp2/convert.c +++ b/src/bin/jp2/convert.c @@ -2067,10 +2067,26 @@ int imagetopnm(opj_image_t * image, const char *outfile, int force_split) has_alpha = (ncomp == 4 || ncomp == 2); red = image->comps[0].data; + if (red == NULL) { + fprintf(stderr, + "imagetopnm: planes[%d] == NULL.\n", 0); + fprintf(stderr, "\tAborting\n"); + fclose(fdest); + return fails; + } if (triple) { green = image->comps[1].data; blue = image->comps[2].data; + for (i = 1; i <= 2; i++) { + if (image->comps[i].data == NULL) { + fprintf(stderr, + "imagetopnm: planes[%d] == NULL.\n", i); + fprintf(stderr, "\tAborting\n"); + fclose(fdest); + return fails; + } + } } else { green = blue = NULL; } |
