diff options
| author | Young_X <YangX92@hotmail.com> | 2018-11-23 15:58:23 +0800 |
|---|---|---|
| committer | Young_X <YangX92@hotmail.com> | 2018-11-23 17:08:57 +0800 |
| commit | 46822d0eddc3324b2a056bc60ffa997027bebd66 (patch) | |
| tree | a9ebe4c912edc5448cc8cc0143cc8ca7decb7e26 /src | |
| parent | 619e1b086eaa21ebd9b23eb67deee543b07bf06f (diff) | |
[JPWL] imagetotga(): fix read heap buffer overflow if numcomps < 3 (#987)
Signed-off-by: Young_X <YangX92@hotmail.com>
Diffstat (limited to 'src')
| -rw-r--r-- | src/bin/jpwl/convert.c | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/src/bin/jpwl/convert.c b/src/bin/jpwl/convert.c index 04ca64ca..4f636c17 100644 --- a/src/bin/jpwl/convert.c +++ b/src/bin/jpwl/convert.c @@ -445,7 +445,7 @@ int imagetotga(opj_image_t * image, const char *outfile) { int width, height, bpp, x, y; opj_bool write_alpha; - int i, adjustR, adjustG, adjustB; + int i, adjustR, adjustG = 0, adjustB = 0; unsigned int alpha_channel; float r, g, b, a; unsigned char value; @@ -486,8 +486,10 @@ int imagetotga(opj_image_t * image, const char *outfile) scale = 255.0f / (float)((1 << image->comps[0].prec) - 1); adjustR = (image->comps[0].sgnd ? 1 << (image->comps[0].prec - 1) : 0); - adjustG = (image->comps[1].sgnd ? 1 << (image->comps[1].prec - 1) : 0); - adjustB = (image->comps[2].sgnd ? 1 << (image->comps[2].prec - 1) : 0); + if (image->numcomps >= 3) { + adjustG = (image->comps[1].sgnd ? 1 << (image->comps[1].prec - 1) : 0); + adjustB = (image->comps[2].sgnd ? 1 << (image->comps[2].prec - 1) : 0); + } for (y = 0; y < height; y++) { unsigned int index = y * width; |
