summaryrefslogtreecommitdiff
path: root/pdf
diff options
context:
space:
mode:
authorRobin Watts <robin.watts@artifex.com>2012-03-12 14:13:48 +0000
committerRobin Watts <robin.watts@artifex.com>2012-03-12 14:13:48 +0000
commitbc9e8f1d6c18b8b37678a07e9266f269fe5bf0dc (patch)
tree73be383b57ee4726f2a272ddeb9f6e895390aff2 /pdf
parent3db3054ec8223b6bd01d8d8144b4863c9ca8fd2d (diff)
parentcaf8e7a6c7cfeb245cdb5ac44d310a82ab0155b3 (diff)
downloadmupdf-bc9e8f1d6c18b8b37678a07e9266f269fe5bf0dc.tar.xz
Merge branch 'master' into header-split
Diffstat (limited to 'pdf')
-rw-r--r--pdf/pdf_function.c29
1 files changed, 22 insertions, 7 deletions
diff --git a/pdf/pdf_function.c b/pdf/pdf_function.c
index 159515c1..e1c53beb 100644
--- a/pdf/pdf_function.c
+++ b/pdf/pdf_function.c
@@ -203,7 +203,13 @@ ps_push_real(ps_stack *st, float n)
if (!ps_overflow(st, 1))
{
st->stack[st->sp].type = PS_REAL;
- st->stack[st->sp].u.f = n;
+ if (isnan(n))
+ {
+ /* Push 1.0, as it's a small known value that won't
+ cause a divide by 0. Same reason as in fz_atof. */
+ n = 1.0;
+ }
+ st->stack[st->sp].u.f = CLAMP(n, -FLT_MAX, FLT_MAX);
st->sp++;
}
}
@@ -360,10 +366,10 @@ ps_run(fz_context *ctx, psobj *code, ps_stack *st, int pc)
case PS_OP_BITSHIFT:
i2 = ps_pop_int(st);
i1 = ps_pop_int(st);
- if (i2 > 0)
+ if (i2 > 0 && i2 < 8 * sizeof (i2))
ps_push_int(st, i1 << i2);
- else if (i2 < 0)
- ps_push_int(st, (int)((unsigned int)i1 >> i2));
+ else if (i2 < 0 && i2 > -8 * (int)sizeof (i2))
+ ps_push_int(st, (int)((unsigned int)i1 >> -i2));
else
ps_push_int(st, i1);
break;
@@ -393,7 +399,10 @@ ps_run(fz_context *ctx, psobj *code, ps_stack *st, int pc)
case PS_OP_DIV:
r2 = ps_pop_real(st);
r1 = ps_pop_real(st);
- ps_push_real(st, r1 / r2);
+ if (fabsf(r2) < FLT_EPSILON)
+ ps_push_real(st, r1 / r2);
+ else
+ ps_push_real(st, DIV_BY_ZERO(r1, r2, -FLT_MAX, FLT_MAX));
break;
case PS_OP_DUP:
@@ -466,7 +475,10 @@ ps_run(fz_context *ctx, psobj *code, ps_stack *st, int pc)
case PS_OP_IDIV:
i2 = ps_pop_int(st);
i1 = ps_pop_int(st);
- ps_push_int(st, i1 / i2);
+ if (i2 != 0)
+ ps_push_int(st, i1 / i2);
+ else
+ ps_push_int(st, DIV_BY_ZERO(i1, i2, INT_MIN, INT_MAX));
break;
case PS_OP_INDEX:
@@ -512,7 +524,10 @@ ps_run(fz_context *ctx, psobj *code, ps_stack *st, int pc)
case PS_OP_MOD:
i2 = ps_pop_int(st);
i1 = ps_pop_int(st);
- ps_push_int(st, i1 % i2);
+ if (i2 != 0)
+ ps_push_int(st, i1 % i2);
+ else
+ ps_push_int(st, DIV_BY_ZERO(i1, i2, INT_MIN, INT_MAX));
break;
case PS_OP_MUL: