summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
authorSebastian Rasmussen <sebras@gmail.com>2018-10-31 15:56:11 +0100
committerSebastian Rasmussen <sebras@gmail.com>2019-09-04 05:14:41 +0200
commitf3ee448815eb992b8d4746e32c05e8289f30415f (patch)
treec57673ce38422ace3bc503a2305770ccfad4e17e /src/lib
parentd801bd4e6287d13b65a48775ebd43fca350b21d9 (diff)
openjp2/j2k: Validate all SGcod/SPcod/SPcoc parameter values.
Previously the multiple component transformation SGcod(C) and wavelet transformation SPcod(H)/SPcoc(E) parameter values were never checked, allowing for out of range values. The lack of validation allowed the bit stream provided in issue #1158 through. After this commit an error message points to the marker segments' parameters as being out of range. input/nonregression/edf_c2_20.jp2 contains an SPcod(H) value of 17, but according to Table A-20 of the specification only values 0 and 1 are valid. input/nonregression/issue826.jp2 contains a SGcod(B) value of 2, but according to Table A-17 of the specification only values 0 and 1 are valid. input/nonregression/oss-fuzz2785.jp2 contains a SGcod(B) value of 32, but it is likewise limited to 0 or 1. These test cases have been updated to consistently fail to parse the headers since they contain out of bounds values. This fixes issue #1210.
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/openjp2/j2k.c12
1 files changed, 12 insertions, 0 deletions
diff --git a/src/lib/openjp2/j2k.c b/src/lib/openjp2/j2k.c
index 59b2bbb7..43be7677 100644
--- a/src/lib/openjp2/j2k.c
+++ b/src/lib/openjp2/j2k.c
@@ -2698,6 +2698,12 @@ static OPJ_BOOL opj_j2k_read_cod(opj_j2k_t *p_j2k,
opj_read_bytes(p_header_data, &l_tcp->mct, 1); /* SGcod (C) */
++p_header_data;
+ if (l_tcp->mct > 1) {
+ opj_event_msg(p_manager, EVT_ERROR,
+ "Invalid multiple component transformation\n");
+ return OPJ_FALSE;
+ }
+
p_header_size -= 5;
for (i = 0; i < l_image->numcomps; ++i) {
l_tcp->tccps[i].csty = l_tcp->csty & J2K_CCP_CSTY_PRT;
@@ -9792,6 +9798,12 @@ static OPJ_BOOL opj_j2k_read_SPCod_SPCoc(opj_j2k_t *p_j2k,
opj_read_bytes(l_current_ptr, &l_tccp->qmfbid, 1);
++l_current_ptr;
+ if (l_tccp->qmfbid > 1) {
+ opj_event_msg(p_manager, EVT_ERROR,
+ "Error reading SPCod SPCoc element, Invalid transformation found\n");
+ return OPJ_FALSE;
+ }
+
*p_header_size = *p_header_size - 5;
/* use custom precinct size ? */