diff options
author | Ken Sharp <ken.sharp@artifex.com> | 2022-03-21 11:10:42 +0000 |
---|---|---|
committer | Chris Liddell <chris.liddell@artifex.com> | 2022-03-21 16:31:06 +0000 |
commit | 6abd758e502a2cd71045f3db5496ff85478f0abb (patch) | |
tree | 783e3ff54c03bced592e7eb39dab354d27361e4f | |
parent | 5da13fe8c2fe685f3878d64df5bd55ad2a1b59c2 (diff) | |
download | ghostpdl-6abd758e502a2cd71045f3db5496ff85478f0abb.tar.gz |
OSS-fuzz 45886 - validate funtion parameters for transfer functions
This was causing a buffer overrun when evaluating a transfer function
because the code assumed it would be a 1-in one-out function, whereas
the supplied function is a 1-in 3-out function, causing it to overrun
the output buffer.
This commit checks that the function is a 1-in, 1-out function and
returns an error if it isn't.
Similar fix applied for colour transfers, and a C++ commented out line
removed as it seemed to be entirely spurious.
-rw-r--r-- | pdf/pdf_gstate.c | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/pdf/pdf_gstate.c b/pdf/pdf_gstate.c index 7801ee681..c1444b4b5 100644 --- a/pdf/pdf_gstate.c +++ b/pdf/pdf_gstate.c @@ -875,6 +875,11 @@ static int pdfi_set_all_transfers(pdf_context *ctx, pdf_array *a, pdf_dict *page pdfi_countdown(o); goto exit; } + if (pfn[i]->params.m != 1 || pfn[i]->params.n != 1) { + pdfi_countdown(o); + code = gs_note_error(gs_error_rangecheck); + goto exit; + } } else { pdfi_countdown(o); code = gs_note_error(gs_error_typecheck); @@ -938,7 +943,6 @@ static int pdfi_set_all_transfers(pdf_context *ctx, pdf_array *a, pdf_dict *page } } exit: -// (void)pdfi_seek(ctx, ctx->main_stream, saved_stream_offset, SEEK_SET); for (i = 0; i < 4; i++) { pdfi_free_function(ctx, pfn[i]); } @@ -957,6 +961,11 @@ static int pdfi_set_gray_transfer(pdf_context *ctx, pdf_obj *tr_obj, pdf_dict *p if (code < 0) return code; + if (pfn->params.m != 1 || pfn->params.n != 1) { + (void)pdfi_free_function(ctx, pfn); + return_error(gs_error_rangecheck); + } + gs_settransfer_remap(ctx->pgs, gs_mapped_transfer, false); for (i = 0; i < transfer_map_size; i++) { float v, f; |