diff options
author | thestig <thestig@chromium.org> | 2016-05-19 10:36:16 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-05-19 10:36:16 -0700 |
commit | 225a257ba299a43c02471fa46c22ba94da1f3f09 (patch) | |
tree | 85f1fe8fb746ac484ce5908558eaad1d3f6a9433 /third_party/libopenjpeg20 | |
parent | 23467939aff1273c9b8e084fa83b2a2436d67526 (diff) | |
download | pdfium-225a257ba299a43c02471fa46c22ba94da1f3f09.tar.xz |
Fix a memory leak in opj_jp2_read_ihdr().
BUG=603895
Review-Url: https://codereview.chromium.org/1992893003
Diffstat (limited to 'third_party/libopenjpeg20')
-rw-r--r-- | third_party/libopenjpeg20/0014-opj_jp2_read_ihdr_leak.patch | 28 | ||||
-rw-r--r-- | third_party/libopenjpeg20/README.pdfium | 1 | ||||
-rw-r--r-- | third_party/libopenjpeg20/jp2.c | 3 |
3 files changed, 31 insertions, 1 deletions
diff --git a/third_party/libopenjpeg20/0014-opj_jp2_read_ihdr_leak.patch b/third_party/libopenjpeg20/0014-opj_jp2_read_ihdr_leak.patch new file mode 100644 index 0000000000..f5645330a3 --- /dev/null +++ b/third_party/libopenjpeg20/0014-opj_jp2_read_ihdr_leak.patch @@ -0,0 +1,28 @@ +diff --git a/third_party/libopenjpeg20/jp2.c b/third_party/libopenjpeg20/jp2.c +index 3bcb42e..a6648f6 100644 +--- a/third_party/libopenjpeg20/jp2.c ++++ b/third_party/libopenjpeg20/jp2.c +@@ -561,6 +561,7 @@ static OPJ_BOOL opj_jp2_read_ihdr( opj_jp2_t *jp2, + p_image_header_data += 2; + + /* allocate memory for components */ ++ opj_free(jp2->comps); + jp2->comps = (opj_jp2_comps_t*) opj_calloc(jp2->numcomps, sizeof(opj_jp2_comps_t)); + if (jp2->comps == 0) { + opj_event_msg(p_manager, EVT_ERROR, "Not enough memory to handle image header (ihdr)\n"); +@@ -1758,6 +1759,7 @@ void opj_jp2_setup_decoder(opj_jp2_t *jp2, opj_dparameters_t *parameters) + + /* further JP2 initializations go here */ + jp2->color.jp2_has_colr = 0; ++ jp2->comps = NULL; + jp2->ignore_pclr_cmap_cdef = parameters->flags & OPJ_DPARAMETERS_IGNORE_PCLR_CMAP_CDEF_FLAG; + } + +@@ -1815,7 +1817,6 @@ OPJ_BOOL opj_jp2_setup_encoder( opj_jp2_t *jp2, + jp2->numcomps = image->numcomps; /* NC */ + jp2->comps = (opj_jp2_comps_t*) opj_malloc(jp2->numcomps * sizeof(opj_jp2_comps_t)); + if (!jp2->comps) { +- jp2->comps = NULL; + opj_event_msg(p_manager, EVT_ERROR, "Not enough memory when setup the JP2 encoder\n"); + /* Memory of jp2->cl will be freed by opj_jp2_destroy */ + return OPJ_FALSE; diff --git a/third_party/libopenjpeg20/README.pdfium b/third_party/libopenjpeg20/README.pdfium index a8f83c36a2..82a3754482 100644 --- a/third_party/libopenjpeg20/README.pdfium +++ b/third_party/libopenjpeg20/README.pdfium @@ -23,4 +23,5 @@ Local Modifications: 0011-j2k_update_image_data.patch: Prevent bad signed -> unsigned casting. 0012-mct_sse.patch: Don't use SSE intrinsics in 32-bit builds. 0013-attrib_fix.patch: Don't needlessly redefine __attribute__, https://github.com/uclouvain/openjpeg/issues/727 +0014-opj_jp2_read_ihdr_leak.patch: Memory leak in opj_jp2_read_ihdr(). TODO(thestig): List all the other patches. diff --git a/third_party/libopenjpeg20/jp2.c b/third_party/libopenjpeg20/jp2.c index 3bcb42ea86..a6648f637d 100644 --- a/third_party/libopenjpeg20/jp2.c +++ b/third_party/libopenjpeg20/jp2.c @@ -561,6 +561,7 @@ static OPJ_BOOL opj_jp2_read_ihdr( opj_jp2_t *jp2, p_image_header_data += 2; /* allocate memory for components */ + opj_free(jp2->comps); jp2->comps = (opj_jp2_comps_t*) opj_calloc(jp2->numcomps, sizeof(opj_jp2_comps_t)); if (jp2->comps == 0) { opj_event_msg(p_manager, EVT_ERROR, "Not enough memory to handle image header (ihdr)\n"); @@ -1758,6 +1759,7 @@ void opj_jp2_setup_decoder(opj_jp2_t *jp2, opj_dparameters_t *parameters) /* further JP2 initializations go here */ jp2->color.jp2_has_colr = 0; + jp2->comps = NULL; jp2->ignore_pclr_cmap_cdef = parameters->flags & OPJ_DPARAMETERS_IGNORE_PCLR_CMAP_CDEF_FLAG; } @@ -1815,7 +1817,6 @@ OPJ_BOOL opj_jp2_setup_encoder( opj_jp2_t *jp2, jp2->numcomps = image->numcomps; /* NC */ jp2->comps = (opj_jp2_comps_t*) opj_malloc(jp2->numcomps * sizeof(opj_jp2_comps_t)); if (!jp2->comps) { - jp2->comps = NULL; opj_event_msg(p_manager, EVT_ERROR, "Not enough memory when setup the JP2 encoder\n"); /* Memory of jp2->cl will be freed by opj_jp2_destroy */ return OPJ_FALSE; |