From c145aeb2bf13ac408fc3e8233acca43d4251bbdc Mon Sep 17 00:00:00 2001 From: Oliver Chang Date: Tue, 23 Feb 2016 12:41:41 -0800 Subject: openjpeg: Prevent bad cast in opj_j2k_update_image_data R=tsepez@chromium.org BUG=587227 Review URL: https://codereview.chromium.org/1726843002 . --- .../libopenjpeg20/0011-j2k_update_image_data.patch | 17 +++++++++++++++++ third_party/libopenjpeg20/README.pdfium | 1 + third_party/libopenjpeg20/j2k.c | 6 ++++++ 3 files changed, 24 insertions(+) create mode 100644 third_party/libopenjpeg20/0011-j2k_update_image_data.patch diff --git a/third_party/libopenjpeg20/0011-j2k_update_image_data.patch b/third_party/libopenjpeg20/0011-j2k_update_image_data.patch new file mode 100644 index 0000000000..697c48f18b --- /dev/null +++ b/third_party/libopenjpeg20/0011-j2k_update_image_data.patch @@ -0,0 +1,17 @@ +diff --git a/third_party/libopenjpeg20/j2k.c b/third_party/libopenjpeg20/j2k.c +index b20f219..9056feb 100644 +--- a/third_party/libopenjpeg20/j2k.c ++++ b/third_party/libopenjpeg20/j2k.c +@@ -8211,6 +8211,12 @@ static OPJ_BOOL opj_j2k_update_image_data (opj_tcd_t * p_tcd, OPJ_BYTE * p_data, + * */ + assert( l_res->x0 >= 0); + assert( l_res->x1 >= 0); ++ ++ /* Prevent bad casting to unsigned values in the subsequent lines. */ ++ if ( l_res->x0 < 0 || l_res->x1 < 0 || l_res->y0 < 0 || l_res->y1 < 0 ) { ++ return OPJ_FALSE; ++ } ++ + if ( l_x0_dest < (OPJ_UINT32)l_res->x0 ) { + l_start_x_dest = (OPJ_UINT32)l_res->x0 - l_x0_dest; + l_offset_x0_src = 0; diff --git a/third_party/libopenjpeg20/README.pdfium b/third_party/libopenjpeg20/README.pdfium index c4d89769a3..0a60ed7691 100644 --- a/third_party/libopenjpeg20/README.pdfium +++ b/third_party/libopenjpeg20/README.pdfium @@ -20,4 +20,5 @@ Local Modifications: 0008-jp2_check_color.patch: Replace an assertion with returning false. 0009-opj_pi_next.patch: Fix potential bad precno value in opj_pi_next* functions. 0010-pi_update_decode_poc.patch: Set proper upper bound for an array in opj_pi_update_decode_poc(). +0011-j2k_update_image_data.patch: Prevent bad signed -> unsigned casting. TODO(thestig): List all the other patches. diff --git a/third_party/libopenjpeg20/j2k.c b/third_party/libopenjpeg20/j2k.c index b20f219bf1..9056feb29a 100644 --- a/third_party/libopenjpeg20/j2k.c +++ b/third_party/libopenjpeg20/j2k.c @@ -8211,6 +8211,12 @@ static OPJ_BOOL opj_j2k_update_image_data (opj_tcd_t * p_tcd, OPJ_BYTE * p_data, * */ assert( l_res->x0 >= 0); assert( l_res->x1 >= 0); + + /* Prevent bad casting to unsigned values in the subsequent lines. */ + if ( l_res->x0 < 0 || l_res->x1 < 0 || l_res->y0 < 0 || l_res->y1 < 0 ) { + return OPJ_FALSE; + } + if ( l_x0_dest < (OPJ_UINT32)l_res->x0 ) { l_start_x_dest = (OPJ_UINT32)l_res->x0 - l_x0_dest; l_offset_x0_src = 0; -- cgit v1.2.3