summaryrefslogtreecommitdiff
path: root/pdf/pdf_function.c
diff options
context:
space:
mode:
authorSebastian Rasmussen <sebras@gmail.com>2012-07-19 01:14:17 +0200
committerTor Andersson <tor.andersson@artifex.com>2012-07-23 18:07:05 +0200
commitc2f34a9605cbd3f59fa2a02ffdbd1d655e11cd42 (patch)
tree0b055bdc9b6e07d7a686d59682773f574f5693b2 /pdf/pdf_function.c
parentec6e8442e47220d0f4e95360ccb94ad3ce6df7f6 (diff)
downloadmupdf-c2f34a9605cbd3f59fa2a02ffdbd1d655e11cd42.tar.xz
Warn about out of range values for exponential pdf functions
Exponential pdf functions have constraints on their input values so warn about out of range values when loading those functions. When evaluation the functions, assume zero without warning.
Diffstat (limited to 'pdf/pdf_function.c')
-rw-r--r--pdf/pdf_function.c24
1 files changed, 18 insertions, 6 deletions
diff --git a/pdf/pdf_function.c b/pdf/pdf_function.c
index 5eea4125..005572df 100644
--- a/pdf/pdf_function.c
+++ b/pdf/pdf_function.c
@@ -1137,10 +1137,25 @@ load_exponential_func(fz_context *ctx, pdf_function *func, pdf_obj *dict)
func->m = 1;
obj = pdf_dict_gets(dict, "N");
- if (!pdf_is_int(obj) && !pdf_is_real(obj))
- fz_throw(ctx, "malformed /N");
func->u.e.n = pdf_to_real(obj);
+ /* See exponential functions (PDF 1.7 section 3.9.2) */
+ if (func->u.e.n != (int) func->u.e.n)
+ {
+ /* If N is non-integer, input values may never be negative */
+ for (i = 0; i < func->m; i++)
+ if (func->domain[i][0] < 0 || func->domain[i][1] < 0)
+ fz_warn(ctx, "exponential function input domain includes illegal negative input values");
+ }
+ else if (func->u.e.n < 0)
+ {
+ /* if N is negative, input values may never be zero */
+ for (i = 0; i < func->m; i++)
+ if (func->domain[i][0] == 0 || func->domain[i][1] == 0 ||
+ (func->domain[i][0] < 0 && func->domain[i][1] > 0))
+ fz_warn(ctx, "exponential function input domain includes illegal input value zero");
+ }
+
obj = pdf_dict_gets(dict, "C0");
if (pdf_is_array(obj))
{
@@ -1181,12 +1196,9 @@ eval_exponential_func(fz_context *ctx, pdf_function *func, float in, float *out)
x = fz_clamp(x, func->domain[0][0], func->domain[0][1]);
- /* constraint */
+ /* Default output is zero, which is suitable for violated constraints */
if ((func->u.e.n != (int)func->u.e.n && x < 0) || (func->u.e.n < 0 && x == 0))
- {
- fz_warn(ctx, "constraint error");
return;
- }
tmp = powf(x, func->u.e.n);
for (i = 0; i < func->n; i++)