summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthieu Darbois <mayeut@users.noreply.github.com>2015-07-21 00:47:23 +0200
committerMatthieu Darbois <mayeut@users.noreply.github.com>2015-07-21 00:47:23 +0200
commit2c7dab765505bac8dcda2be57dbfc2ab985cd4f9 (patch)
tree5c0b5fe128a2c4c9bd40aaddfc7d449727d2f493
parentfd1f7cf297cd1adcdc858dfe6bdd493c5c510a33 (diff)
parent96ae1b8dfc0a38d1afe4902b0e4770c95f491a83 (diff)
Merge pull request #534 from mayeut/issue-235
Add checks for odd looking cmap & for cmap outside jp2h box
-rw-r--r--src/lib/openjp2/jp2.c37
-rw-r--r--tests/nonregression/md5refs.txt3
-rw-r--r--tests/nonregression/test_suite.ctest.in4
3 files changed, 43 insertions, 1 deletions
diff --git a/src/lib/openjp2/jp2.c b/src/lib/openjp2/jp2.c
index aafbe199..543832c4 100644
--- a/src/lib/openjp2/jp2.c
+++ b/src/lib/openjp2/jp2.c
@@ -907,6 +907,23 @@ static OPJ_BOOL opj_jp2_check_color(opj_image_t *image, opj_jp2_color_t *color,
is_sane = OPJ_FALSE;
}
}
+ /* Issue 235/447 weird cmap */
+ if (1 && is_sane && (image->numcomps==1U)) {
+ for (i = 0; i < nr_channels; i++) {
+ if (!pcol_usage[i]) {
+ is_sane = 0U;
+ opj_event_msg(p_manager, EVT_WARNING, "Component mapping seems wrong. Trying to correct.\n", i);
+ break;
+ }
+ }
+ if (!is_sane) {
+ is_sane = OPJ_TRUE;
+ for (i = 0; i < nr_channels; i++) {
+ cmap[i].mtyp = 1U;
+ cmap[i].pcol = (OPJ_BYTE) i;
+ }
+ }
+ }
opj_free(pcol_usage);
if (!is_sane) {
return OPJ_FALSE;
@@ -1990,6 +2007,7 @@ OPJ_BOOL opj_jp2_read_header_procedure( opj_jp2_t *jp2,
opj_jp2_box_t box;
OPJ_UINT32 l_nb_bytes_read;
const opj_jp2_header_handler_t * l_current_handler;
+ const opj_jp2_header_handler_t * l_current_handler_misplaced;
OPJ_UINT32 l_last_data_size = OPJ_BOX_SIZE;
OPJ_UINT32 l_current_data_size;
OPJ_BYTE * l_current_data = 00;
@@ -2033,9 +2051,26 @@ OPJ_BOOL opj_jp2_read_header_procedure( opj_jp2_t *jp2,
}
l_current_handler = opj_jp2_find_handler(box.type);
+ l_current_handler_misplaced = opj_jp2_img_find_handler(box.type);
l_current_data_size = box.length - l_nb_bytes_read;
- if (l_current_handler != 00) {
+ if ((l_current_handler != 00) || (l_current_handler_misplaced != 00)) {
+ if (l_current_handler == 00) {
+ opj_event_msg(p_manager, EVT_WARNING, "Found a misplaced '%c%c%c%c' box outside jp2h box\n", (OPJ_BYTE)(box.type>>24), (OPJ_BYTE)(box.type>>16), (OPJ_BYTE)(box.type>>8), (OPJ_BYTE)(box.type>>0));
+ if (jp2->jp2_state & JP2_STATE_HEADER) {
+ /* read anyway, we already have jp2h */
+ l_current_handler = l_current_handler_misplaced;
+ } else {
+ opj_event_msg(p_manager, EVT_WARNING, "JPEG2000 Header box not read yet, '%c%c%c%c' box will be ignored\n", (OPJ_BYTE)(box.type>>24), (OPJ_BYTE)(box.type>>16), (OPJ_BYTE)(box.type>>8), (OPJ_BYTE)(box.type>>0));
+ jp2->jp2_state |= JP2_STATE_UNKNOWN;
+ if (opj_stream_skip(stream,l_current_data_size,p_manager) != l_current_data_size) {
+ opj_event_msg(p_manager, EVT_ERROR, "Problem with skipping JPEG2000 box, stream error\n");
+ opj_free(l_current_data);
+ return OPJ_FALSE;
+ }
+ continue;
+ }
+ }
if ((OPJ_OFF_T)l_current_data_size > opj_stream_get_number_byte_left(stream)) {
/* do not even try to malloc if we can't read */
opj_event_msg(p_manager, EVT_ERROR, "Invalid box size %d for box '%c%c%c%c'. Need %d bytes, %d bytes remaining \n", box.length, (OPJ_BYTE)(box.type>>24), (OPJ_BYTE)(box.type>>16), (OPJ_BYTE)(box.type>>8), (OPJ_BYTE)(box.type>>0), l_current_data_size, (OPJ_UINT32)opj_stream_get_number_byte_left(stream));
diff --git a/tests/nonregression/md5refs.txt b/tests/nonregression/md5refs.txt
index 3465b099..07f89de0 100644
--- a/tests/nonregression/md5refs.txt
+++ b/tests/nonregression/md5refs.txt
@@ -218,3 +218,6 @@ cfe04d15cf9d615fc36357dcb3b3956b p0_14_tif-1.tif
b6f71c941e3a5b8d2547792ccec58d54 p0_14_tif-4.tif
81fcdd90917efb95aed94c6522d1c188 p0_14_tif-6.tif
6808377b760b4ef3559ba8b14ed9b91a p0_14_tif-8.tif
+dd15b3d487d36a3682be0679300a4319 issue235.jp2_0.pgx
+b9cd6dc76b141fb1fec15f50c1f70e01 issue235.jp2_1.pgx
+3edef2ae197ef30b08deda1b28825399 issue235.jp2_2.pgx
diff --git a/tests/nonregression/test_suite.ctest.in b/tests/nonregression/test_suite.ctest.in
index b8e63f8b..31244add 100644
--- a/tests/nonregression/test_suite.ctest.in
+++ b/tests/nonregression/test_suite.ctest.in
@@ -443,3 +443,7 @@ opj_decompress -i @INPUT_NR_PATH@/basn6a08.jp2 -o @TEMP_PATH@/basn6a08_tif-10.ti
opj_decompress -i @INPUT_NR_PATH@/basn6a08.jp2 -o @TEMP_PATH@/basn6a08_tif-12.tif -p 12S
opj_decompress -i @INPUT_NR_PATH@/basn6a08.jp2 -o @TEMP_PATH@/basn6a08_tif-14.tif -p 14S
opj_decompress -i @INPUT_NR_PATH@/basn6a08.jp2 -o @TEMP_PATH@/basn6a08_tif-16.tif -p 16S
+
+#issue 235 CMAP outside jp2h box. CMAP is buggy
+opj_decompress -i @INPUT_NR_PATH@/issue235.jp2 -o @TEMP_PATH@/issue235.jp2.pgx
+