From 8804940c9a394ff23d641a8cf2efd5300dc87f9e Mon Sep 17 00:00:00 2001 From: Nicolas Pena Date: Tue, 24 Jan 2017 10:41:59 -0500 Subject: Check m_data!=null when adding mct MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit m_decorrelation_array and m_offset_array can be assigned to l_mct_data, which can be set in opj_j2k_read_mct. In this method, there can be an early true return before allocating m_data but after freeing it. BUG=678342 Change-Id: Id9ea3cc57a9a278deb1540e5db8a94db86018fd6 Reviewed-on: https://pdfium-review.googlesource.com/2350 Commit-Queue: Nicolás Peña Commit-Queue: dsinclair Reviewed-by: dsinclair --- .../0025-opj_j2k_add_mct_null_data.patch | 22 ++++++++++++++++++++++ third_party/libopenjpeg20/README.pdfium | 1 + third_party/libopenjpeg20/j2k.c | 4 ++-- 3 files changed, 25 insertions(+), 2 deletions(-) create mode 100644 third_party/libopenjpeg20/0025-opj_j2k_add_mct_null_data.patch (limited to 'third_party') diff --git a/third_party/libopenjpeg20/0025-opj_j2k_add_mct_null_data.patch b/third_party/libopenjpeg20/0025-opj_j2k_add_mct_null_data.patch new file mode 100644 index 0000000000..4a371e5c88 --- /dev/null +++ b/third_party/libopenjpeg20/0025-opj_j2k_add_mct_null_data.patch @@ -0,0 +1,22 @@ +diff --git a/third_party/libopenjpeg20/j2k.c b/third_party/libopenjpeg20/j2k.c +index 5de89cf0e..400ca8098 100644 +--- a/third_party/libopenjpeg20/j2k.c ++++ b/third_party/libopenjpeg20/j2k.c +@@ -5715,7 +5715,7 @@ static OPJ_BOOL opj_j2k_add_mct(opj_tcp_t * p_tcp, opj_image_t * p_image, OPJ_UI + + if (l_deco_array) { + l_data_size = MCT_ELEMENT_SIZE[l_deco_array->m_element_type] * p_image->numcomps * p_image->numcomps; +- if (l_deco_array->m_data_size != l_data_size) { ++ if (l_deco_array->m_data_size != l_data_size || ! l_deco_array->m_data) { + return OPJ_FALSE; + } + +@@ -5734,7 +5734,7 @@ static OPJ_BOOL opj_j2k_add_mct(opj_tcp_t * p_tcp, opj_image_t * p_image, OPJ_UI + + if (l_offset_array) { + l_data_size = MCT_ELEMENT_SIZE[l_offset_array->m_element_type] * p_image->numcomps; +- if (l_offset_array->m_data_size != l_data_size) { ++ if (l_offset_array->m_data_size != l_data_size || ! l_offset_array->m_data) { + return OPJ_FALSE; + } + diff --git a/third_party/libopenjpeg20/README.pdfium b/third_party/libopenjpeg20/README.pdfium index 0f453373f9..093f7fe9bd 100644 --- a/third_party/libopenjpeg20/README.pdfium +++ b/third_party/libopenjpeg20/README.pdfium @@ -34,4 +34,5 @@ Local Modifications: 0022-jp2_apply_pclr_overflow.patch: Prevent integer overflow in opj_jp2_apply_pclr. 0023-opj_j2k_read_mct_records.patch: Fix opj_j2k_read to prevent heap-use-after-free. 0024-l_marker_size_check.patch: Return error before overflow in opj_j2k_read_header_procedure. +0025-opj_j2k_add_mct_null_data.patch: Check m_data != null before trying to read from it. TODO(thestig): List all the other patches. diff --git a/third_party/libopenjpeg20/j2k.c b/third_party/libopenjpeg20/j2k.c index 5de89cf0e7..400ca80984 100644 --- a/third_party/libopenjpeg20/j2k.c +++ b/third_party/libopenjpeg20/j2k.c @@ -5715,7 +5715,7 @@ static OPJ_BOOL opj_j2k_add_mct(opj_tcp_t * p_tcp, opj_image_t * p_image, OPJ_UI if (l_deco_array) { l_data_size = MCT_ELEMENT_SIZE[l_deco_array->m_element_type] * p_image->numcomps * p_image->numcomps; - if (l_deco_array->m_data_size != l_data_size) { + if (l_deco_array->m_data_size != l_data_size || ! l_deco_array->m_data) { return OPJ_FALSE; } @@ -5734,7 +5734,7 @@ static OPJ_BOOL opj_j2k_add_mct(opj_tcp_t * p_tcp, opj_image_t * p_image, OPJ_UI if (l_offset_array) { l_data_size = MCT_ELEMENT_SIZE[l_offset_array->m_element_type] * p_image->numcomps; - if (l_offset_array->m_data_size != l_data_size) { + if (l_offset_array->m_data_size != l_data_size || ! l_offset_array->m_data) { return OPJ_FALSE; } -- cgit v1.2.3