From e82910771b7896b0cfff98b04d2ffe0a56cae0b4 Mon Sep 17 00:00:00 2001 From: Tor Andersson Date: Thu, 7 Jul 2016 15:27:27 +0200 Subject: Safe defaults for pdf_to_rect and pdf_to_matrix. Return the empty rectangle and identity matrix when the pdf object is missing or not an array. --- source/pdf/pdf-parse.c | 38 ++++++++++++++++++++++++-------------- 1 file changed, 24 insertions(+), 14 deletions(-) (limited to 'source/pdf') diff --git a/source/pdf/pdf-parse.c b/source/pdf/pdf-parse.c index db1c4293..0db2e2f0 100644 --- a/source/pdf/pdf-parse.c +++ b/source/pdf/pdf-parse.c @@ -3,26 +3,36 @@ fz_rect * pdf_to_rect(fz_context *ctx, pdf_obj *array, fz_rect *r) { - float a = pdf_to_real(ctx, pdf_array_get(ctx, array, 0)); - float b = pdf_to_real(ctx, pdf_array_get(ctx, array, 1)); - float c = pdf_to_real(ctx, pdf_array_get(ctx, array, 2)); - float d = pdf_to_real(ctx, pdf_array_get(ctx, array, 3)); - r->x0 = fz_min(a, c); - r->y0 = fz_min(b, d); - r->x1 = fz_max(a, c); - r->y1 = fz_max(b, d); + if (!pdf_is_array(ctx, array)) + *r = fz_empty_rect; + else + { + float a = pdf_to_real(ctx, pdf_array_get(ctx, array, 0)); + float b = pdf_to_real(ctx, pdf_array_get(ctx, array, 1)); + float c = pdf_to_real(ctx, pdf_array_get(ctx, array, 2)); + float d = pdf_to_real(ctx, pdf_array_get(ctx, array, 3)); + r->x0 = fz_min(a, c); + r->y0 = fz_min(b, d); + r->x1 = fz_max(a, c); + r->y1 = fz_max(b, d); + } return r; } fz_matrix * pdf_to_matrix(fz_context *ctx, pdf_obj *array, fz_matrix *m) { - m->a = pdf_to_real(ctx, pdf_array_get(ctx, array, 0)); - m->b = pdf_to_real(ctx, pdf_array_get(ctx, array, 1)); - m->c = pdf_to_real(ctx, pdf_array_get(ctx, array, 2)); - m->d = pdf_to_real(ctx, pdf_array_get(ctx, array, 3)); - m->e = pdf_to_real(ctx, pdf_array_get(ctx, array, 4)); - m->f = pdf_to_real(ctx, pdf_array_get(ctx, array, 5)); + if (!pdf_is_array(ctx, array)) + *m = fz_identity; + else + { + m->a = pdf_to_real(ctx, pdf_array_get(ctx, array, 0)); + m->b = pdf_to_real(ctx, pdf_array_get(ctx, array, 1)); + m->c = pdf_to_real(ctx, pdf_array_get(ctx, array, 2)); + m->d = pdf_to_real(ctx, pdf_array_get(ctx, array, 3)); + m->e = pdf_to_real(ctx, pdf_array_get(ctx, array, 4)); + m->f = pdf_to_real(ctx, pdf_array_get(ctx, array, 5)); + } return m; } -- cgit v1.2.3