diff options
| author | Even Rouault <even.rouault@spatialys.com> | 2017-07-29 16:29:11 +0200 |
|---|---|---|
| committer | Even Rouault <even.rouault@spatialys.com> | 2017-07-29 16:29:11 +0200 |
| commit | f6551f822fe020843299bd807ec6989abd070b2c (patch) | |
| tree | d38569fc32d68a14b6e02fdc3cccb47382e44557 /src/lib | |
| parent | 9906fbf737692486cebabe98169988d818e2e66a (diff) | |
opj_t1_clbl_decode_processor(): avoid undefined behaviour if roishift >= 31. Fixes https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=2506. Credit to OSS Fuzz
Diffstat (limited to 'src/lib')
| -rw-r--r-- | src/lib/openjp2/t1.c | 24 |
1 files changed, 16 insertions, 8 deletions
diff --git a/src/lib/openjp2/t1.c b/src/lib/openjp2/t1.c index bd615d59..3615a0e6 100644 --- a/src/lib/openjp2/t1.c +++ b/src/lib/openjp2/t1.c @@ -1685,14 +1685,22 @@ static void opj_t1_clbl_decode_processor(void* user_data, opj_tls_t* tls) cblk_h = t1->h; if (tccp->roishift) { - OPJ_INT32 thresh = 1 << tccp->roishift; - for (j = 0; j < cblk_h; ++j) { - for (i = 0; i < cblk_w; ++i) { - OPJ_INT32 val = datap[(j * cblk_w) + i]; - OPJ_INT32 mag = abs(val); - if (mag >= thresh) { - mag >>= tccp->roishift; - datap[(j * cblk_w) + i] = val < 0 ? -mag : mag; + if (tccp->roishift >= 31) { + for (j = 0; j < cblk_h; ++j) { + for (i = 0; i < cblk_w; ++i) { + datap[(j * cblk_w) + i] = 0; + } + } + } else { + OPJ_INT32 thresh = 1 << tccp->roishift; + for (j = 0; j < cblk_h; ++j) { + for (i = 0; i < cblk_w; ++i) { + OPJ_INT32 val = datap[(j * cblk_w) + i]; + OPJ_INT32 mag = abs(val); + if (mag >= thresh) { + mag >>= tccp->roishift; + datap[(j * cblk_w) + i] = val < 0 ? -mag : mag; + } } } } |
