From 2c2d3dc0ed0a72981a50d393d1450ab77e17c91c Mon Sep 17 00:00:00 2001 From: Sebastian Rasmussen Date: Thu, 19 Jul 2012 00:09:49 +0200 Subject: Handle pdf function evaluation with wrong number of inputs/outputs Functions requiring more inputs than available input values will have those inputs set to zero. Similarly functions producing too few outputs will have the remaining output values be set to zero. Any excessive input values or output values will be ignored. --- pdf/pdf_function.c | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/pdf/pdf_function.c b/pdf/pdf_function.c index a0d0336b..202ea822 100644 --- a/pdf/pdf_function.c +++ b/pdf/pdf_function.c @@ -1466,20 +1466,27 @@ pdf_load_function(pdf_document *xref, pdf_obj *dict, int in, int out) } void -pdf_eval_function(fz_context *ctx, pdf_function *func, float *in, int inlen, float *out, int outlen) +pdf_eval_function(fz_context *ctx, pdf_function *func, float *in_, int inlen, float *out_, int outlen) { - memset(out, 0, sizeof(float) * outlen); + float fakein[MAXN]; + float fakeout[MAXN]; + float *in = in_; + float *out = out_; - if (inlen != func->m) + if (inlen < func->m) { - fz_warn(ctx, "tried to evaluate function with wrong number of inputs"); - return; + in = fakein; + memset(in, 0, sizeof(float) * func->m); + memcpy(in, in_, sizeof(float) * inlen); } - if (func->n != outlen) + + if (outlen < func->n) { - fz_warn(ctx, "tried to evaluate function with wrong number of outputs"); - return; + out = fakeout; + memset(out, 0, sizeof(float) * func->n); } + else + memset(out, 0, sizeof(float) * outlen); switch(func->type) { @@ -1488,6 +1495,9 @@ pdf_eval_function(fz_context *ctx, pdf_function *func, float *in, int inlen, flo case STITCHING: eval_stitching_func(ctx, func, *in, out); break; case POSTSCRIPT: eval_postscript_func(ctx, func, in, out); break; } + + if (outlen < func->n) + memcpy(out_, out, sizeof(float) * outlen); } /* -- cgit v1.2.3