From 4b0a8e2a428e38b5084e1f8d678495adbbc61504 Mon Sep 17 00:00:00 2001 From: Sebastian Rasmussen Date: Sat, 29 Sep 2012 02:08:15 +0200 Subject: Give better warnings for out of bounds values in shadings --- pdf/pdf_shade.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/pdf/pdf_shade.c b/pdf/pdf_shade.c index 6fbfd6b7..24ccde6e 100644 --- a/pdf/pdf_shade.c +++ b/pdf/pdf_shade.c @@ -190,6 +190,7 @@ struct mesh_params static void pdf_load_mesh_params(fz_shade *shade, pdf_document *xref, pdf_obj *dict) { + fz_context *ctx = xref->ctx; pdf_obj *obj; int i, n; @@ -221,20 +222,33 @@ pdf_load_mesh_params(fz_shade *shade, pdf_document *xref, pdf_obj *dict) } } - if (shade->u.m.vprow < 2) + if (shade->u.m.vprow < 2 && shade->type == 5) + { + fz_warn(ctx, "Too few vertices per row (%d)", shade->u.m.vprow); shade->u.m.vprow = 2; + } - if (shade->u.m.bpflag != 2 && shade->u.m.bpflag != 4 && shade->u.m.bpflag != 8) + if (shade->u.m.bpflag != 2 && shade->u.m.bpflag != 4 && shade->u.m.bpflag != 8 && + shade->type != 5) + { + fz_warn(ctx, "Invalid number of bits per flag (%d)", shade->u.m.bpflag); shade->u.m.bpflag = 8; + } if (shade->u.m.bpcoord != 1 && shade->u.m.bpcoord != 2 && shade->u.m.bpcoord != 4 && shade->u.m.bpcoord != 8 && shade->u.m.bpcoord != 12 && shade->u.m.bpcoord != 16 && shade->u.m.bpcoord != 24 && shade->u.m.bpcoord != 32) + { + fz_warn(ctx, "Invalid number of bits per coordinate (%d)", shade->u.m.bpcoord); shade->u.m.bpcoord = 8; + } if (shade->u.m.bpcomp != 1 && shade->u.m.bpcomp != 2 && shade->u.m.bpcomp != 4 && shade->u.m.bpcomp != 8 && shade->u.m.bpcomp != 12 && shade->u.m.bpcomp != 16) + { + fz_warn(ctx, "Invalid number of bits per component (%d)", shade->u.m.bpcomp); shade->u.m.bpcomp = 8; + } } static void -- cgit v1.2.3