From e6dfa88940aec6820411fc0d013c2bd0faa5547e Mon Sep 17 00:00:00 2001 From: Sebastian Rasmussen Date: Wed, 9 May 2018 22:15:11 +0800 Subject: Use fz_malloc_no_throw() in JPEG/DCT decoder. Suppose an application that uses MuPDF implements its own allocator that limits the amount of memory that may be allocated. When that condition occurs fz_malloc() will throw an exception, this exception would then be thrown right back to MuPDF without allowing for libjpeg to free any of the memory it has allocated. After this commit fz_malloc_no_throw() is called, which under the same conditions would simply return NULL. allowing for libjpeg to free what ever allocations it has done, and return to MuPDF with an error just like before. --- source/fitz/filter-dct.c | 2 +- source/fitz/load-jpeg.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'source') diff --git a/source/fitz/filter-dct.c b/source/fitz/filter-dct.c index a3ada67e..c3654cf8 100644 --- a/source/fitz/filter-dct.c +++ b/source/fitz/filter-dct.c @@ -46,7 +46,7 @@ static void * fz_dct_mem_alloc(j_common_ptr cinfo, size_t size) { fz_dctd *state = JZ_DCT_STATE_FROM_CINFO(cinfo); - return fz_malloc(state->ctx, size); + return fz_malloc_no_throw(state->ctx, size); } static void diff --git a/source/fitz/load-jpeg.c b/source/fitz/load-jpeg.c index 87b32431..3db94a6b 100644 --- a/source/fitz/load-jpeg.c +++ b/source/fitz/load-jpeg.c @@ -24,7 +24,7 @@ static void * fz_jpg_mem_alloc(j_common_ptr cinfo, size_t size) { fz_context *ctx = JZ_CTX_FROM_CINFO(cinfo); - return fz_malloc(ctx, size); + return fz_malloc_no_throw(ctx, size); } static void -- cgit v1.2.3