Skip to content

Commit

Permalink
openjp2/j2k: Validate all SGcod and SPcod parameter values.
Browse files Browse the repository at this point in the history
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 uclouvain#1158 through. After this commit an error message
points to the marker segments' parameters as being out of
range.

This fixes issue uclouvain#1210.
  • Loading branch information
sebras committed Sep 3, 2019
1 parent 1df6ae7 commit eafe80d
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/lib/openjp2/j2k.c
Original file line number Diff line number Diff line change
Expand Up @@ -2698,6 +2698,11 @@ 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;
Expand Down Expand Up @@ -9787,6 +9792,12 @@ static OPJ_BOOL opj_j2k_read_SPCod_SPCoc(opj_j2k_t *p_j2k,
opj_read_bytes(l_current_ptr, &l_tccp->qmfbid, 1); /* SPcod (H) / SPcoc (E) */
++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 ? */
Expand Down

0 comments on commit eafe80d

Please sign in to comment.