diff options
author | Sebastian Rasmussen <sebras@gmail.com> | 2012-07-19 00:09:49 +0200 |
---|---|---|
committer | Tor Andersson <tor.andersson@artifex.com> | 2012-07-23 18:07:04 +0200 |
commit | 2c2d3dc0ed0a72981a50d393d1450ab77e17c91c (patch) | |
tree | b1b999f4aa0f240c22986b845169e10a3ad3ee88 /pdf/pdf_function.c | |
parent | e45df83bf0e7df8fc6e710fcdf6baee97863d780 (diff) | |
download | mupdf-2c2d3dc0ed0a72981a50d393d1450ab77e17c91c.tar.xz |
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.
Diffstat (limited to 'pdf/pdf_function.c')
-rw-r--r-- | pdf/pdf_function.c | 26 |
1 files 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); } /* |