summaryrefslogtreecommitdiff
path: root/openjpeg
diff options
context:
space:
mode:
authorSebastian Rasmussen <sebras@gmail.com>2018-10-31 20:22:11 +0100
committerSebastian Rasmussen <sebras@gmail.com>2020-02-06 02:42:12 +0800
commit37fae2058eb7216c60801dfdbd5b9c987446866a (patch)
treef535f739ed02de71dedd87b302c6141371f4eef9 /openjpeg
parent56e3ed1abc84ef0c8a718b458a5734b016e7b8cc (diff)
downloadghostpdl-37fae2058eb7216c60801dfdbd5b9c987446866a.tar.gz
Re-apply fix for bug 700088 lost in openjpeg 2.3.1 upgrade.
The original commit message read: Bug 700088: Report error if all wanted J2K components are not decoded. Ghostscript used to attempt to use even the undecoded components. The source code for upstream's opj_decompress tool avoided this by a workaround along with a comment indicating that this ought to be done in the library (so all clients, e.g. Ghostscript will benefit from it). With this commit the library will error out if not all requested components are successfully decoded. Thus Ghostscript will no longer crash. Reported in https://github.com/uclouvain/openjpeg/issues/1158 sent upstream in https://github.com/uclouvain/openjpeg/pull/1164 and finally committed in e66125fe260deee49fdf6e9978d9bd29871dd5bb
Diffstat (limited to 'openjpeg')
-rw-r--r--openjpeg/src/lib/openjp2/j2k.c44
1 files changed, 44 insertions, 0 deletions
diff --git a/openjpeg/src/lib/openjp2/j2k.c b/openjpeg/src/lib/openjp2/j2k.c
index 4169cd672..8aaa34e8f 100644
--- a/openjpeg/src/lib/openjp2/j2k.c
+++ b/openjpeg/src/lib/openjp2/j2k.c
@@ -10657,6 +10657,42 @@ static OPJ_BOOL opj_j2k_allocate_tile_element_cstr_index(opj_j2k_t *p_j2k)
return OPJ_TRUE;
}
+static OPJ_BOOL opj_j2k_are_all_used_components_decoded(opj_j2k_t *p_j2k,
+ opj_event_mgr_t * p_manager)
+{
+ OPJ_UINT32 compno;
+ OPJ_BOOL decoded_all_used_components = OPJ_TRUE;
+
+ if (p_j2k->m_specific_param.m_decoder.m_numcomps_to_decode) {
+ for (compno = 0;
+ compno < p_j2k->m_specific_param.m_decoder.m_numcomps_to_decode; compno++) {
+ OPJ_UINT32 dec_compno =
+ p_j2k->m_specific_param.m_decoder.m_comps_indices_to_decode[compno];
+ if (p_j2k->m_output_image->comps[dec_compno].data == NULL) {
+ opj_event_msg(p_manager, EVT_WARNING, "Failed to decode component %d\n",
+ dec_compno);
+ decoded_all_used_components = OPJ_FALSE;
+ }
+ }
+ } else {
+ for (compno = 0; compno < p_j2k->m_output_image->numcomps; compno++) {
+ if (p_j2k->m_output_image->comps[compno].data == NULL) {
+ opj_event_msg(p_manager, EVT_WARNING, "Failed to decode component %d\n",
+ compno);
+ decoded_all_used_components = OPJ_FALSE;
+ }
+ }
+ }
+
+ if (decoded_all_used_components == OPJ_FALSE) {
+ opj_event_msg(p_manager, EVT_ERROR, "Failed to decode all used components\n");
+ return OPJ_FALSE;
+ }
+
+ return OPJ_TRUE;
+}
+
+
static OPJ_BOOL opj_j2k_decode_tiles(opj_j2k_t *p_j2k,
opj_stream_private_t *p_stream,
opj_event_mgr_t * p_manager)
@@ -10768,6 +10804,10 @@ static OPJ_BOOL opj_j2k_decode_tiles(opj_j2k_t *p_j2k,
}
}
+ if (! opj_j2k_are_all_used_components_decoded(p_j2k, p_manager)) {
+ return OPJ_FALSE;
+ }
+
return OPJ_TRUE;
}
@@ -10896,6 +10936,10 @@ static OPJ_BOOL opj_j2k_decode_one_tile(opj_j2k_t *p_j2k,
}
+ if (! opj_j2k_are_all_used_components_decoded(p_j2k, p_manager)) {
+ return OPJ_FALSE;
+ }
+
return OPJ_TRUE;
}