summaryrefslogtreecommitdiff
path: root/src/lib/openjp2/jp2.c
diff options
context:
space:
mode:
authorszukw000 <szukw000@arcor.de>2017-07-31 13:58:08 +0200
committerszukw000 <szukw000@arcor.de>2017-07-31 13:58:08 +0200
commit00f45684a8339e69ed55df2397f3c19d09fecaed (patch)
tree171f881e7b3bcad1afed20d69aa7a8c02ec9dad8 /src/lib/openjp2/jp2.c
parent13cde9fa37249628af6b6f10601b733f87a025f4 (diff)
Catch images broken by AFL
Diffstat (limited to 'src/lib/openjp2/jp2.c')
-rw-r--r--src/lib/openjp2/jp2.c17
1 files changed, 17 insertions, 0 deletions
diff --git a/src/lib/openjp2/jp2.c b/src/lib/openjp2/jp2.c
index 1211ab5d..ca7c7158 100644
--- a/src/lib/openjp2/jp2.c
+++ b/src/lib/openjp2/jp2.c
@@ -619,6 +619,11 @@ static OPJ_BOOL opj_jp2_read_ihdr(opj_jp2_t *jp2,
opj_read_bytes(p_image_header_data, &(jp2->IPR), 1); /* IPR */
++ p_image_header_data;
+ jp2->j2k->m_cp.bpc_is_255 = (jp2->bpc == 255); /* For AFL test */
+ jp2->j2k->ihdr_w = jp2->w; /* For AFL test */
+ jp2->j2k->ihdr_h = jp2->h; /* For AFL test */
+ jp2->has_ihdr = 1; /* For AFL test */
+
return OPJ_TRUE;
}
@@ -1573,6 +1578,9 @@ static OPJ_BOOL opj_jp2_read_colr(opj_jp2_t *jp2,
"COLR BOX meth value is not a regular value (%d), "
"so we will ignore the entire Colour Specification box. \n", jp2->meth);
}
+ if (jp2->color.jp2_has_colr) {
+ jp2->j2k->enumcs = jp2->enumcs;
+ }
return OPJ_TRUE;
}
@@ -2733,6 +2741,7 @@ static OPJ_BOOL opj_jp2_read_jp2h(opj_jp2_t *jp2,
}
jp2->jp2_state |= JP2_STATE_HEADER;
+ jp2->has_jp2h = 1;
return OPJ_TRUE;
}
@@ -2838,6 +2847,14 @@ OPJ_BOOL opj_jp2_read_header(opj_stream_private_t *p_stream,
if (! opj_jp2_exec(jp2, jp2->m_procedure_list, p_stream, p_manager)) {
return OPJ_FALSE;
}
+ if (jp2->has_jp2h == 0) { /* AFL test */
+ opj_event_msg(p_manager, EVT_ERROR, "JP2H box missing. Required.\n");
+ return OPJ_FALSE;
+ }
+ if (jp2->has_ihdr == 0) { /* AFL test */
+ opj_event_msg(p_manager, EVT_ERROR, "IHDR box_missing. Required.\n");
+ return OPJ_FALSE;
+ }
return opj_j2k_read_header(p_stream,
jp2->j2k,