Skip to content

Commit

Permalink
Bug 700088: Report error if all wanted J2K components are not decoded.
Browse files Browse the repository at this point in the history
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 uclouvain/openjpeg#1158
sent upstream in uclouvain/openjpeg#1164
and finally committed in e66125f
  • Loading branch information
sebras committed Sep 4, 2019
1 parent 0c286d0 commit 414ed12
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 11 deletions.
11 changes: 0 additions & 11 deletions src/bin/jp2/opj_decompress.c
Original file line number Diff line number Diff line change
Expand Up @@ -1570,17 +1570,6 @@ int main(int argc, char **argv)
}
}

/* FIXME? Shouldn't that situation be considered as an error of */
/* opj_decode() / opj_get_decoded_tile() ? */
if (image->comps[0].data == NULL) {
fprintf(stderr, "ERROR -> opj_decompress: no image data!\n");
opj_destroy_codec(l_codec);
opj_stream_destroy(l_stream);
opj_image_destroy(image);
failed = 1;
goto fin;
}

tCumulative += opj_clock() - t;
numDecompressedImages++;

Expand Down
44 changes: 44 additions & 0 deletions src/lib/openjp2/j2k.c
Original file line number Diff line number Diff line change
Expand Up @@ -10645,6 +10645,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)
Expand Down Expand Up @@ -10756,6 +10792,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;
}

Expand Down Expand Up @@ -10884,6 +10924,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;
}

Expand Down

0 comments on commit 414ed12

Please sign in to comment.