From 2972aa7531a3cd810e245c4fab7ebd71c583fca2 Mon Sep 17 00:00:00 2001 From: Paul Gardiner Date: Fri, 15 Jun 2012 16:25:15 +0100 Subject: Fix bug 693128: MuPDF forms support: crash on button click Fix one pdf_js function that didn't protect agains doc->js == NULL. Also change exception handling in pdf_new_js so that it doesn't abort just because of a single failed stream load. --- pdf/pdf_js.c | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) (limited to 'pdf') diff --git a/pdf/pdf_js.c b/pdf/pdf_js.c index 348382ab..b4cc2a3c 100644 --- a/pdf/pdf_js.c +++ b/pdf/pdf_js.c @@ -288,17 +288,26 @@ pdf_js *pdf_new_js(pdf_document *doc) unsigned char *buf; int len; - fzbuf = pdf_load_stream(doc, pdf_to_num(code), pdf_to_gen(code)); - len = fz_buffer_storage(ctx, fzbuf, &buf); - pdf_jsimp_execute_count(js->imp, buf, len); - fz_drop_buffer(ctx, fzbuf); - fzbuf = NULL; + fz_try(ctx) + { + fzbuf = pdf_load_stream(doc, pdf_to_num(code), pdf_to_gen(code)); + len = fz_buffer_storage(ctx, fzbuf, &buf); + pdf_jsimp_execute_count(js->imp, buf, len); + } + fz_always(ctx) + { + fz_drop_buffer(ctx, fzbuf); + fzbuf = NULL; + } + fz_catch(ctx) + { + fz_warn(ctx, "Warning: %s", ctx->error->message); + } } } } fz_always(ctx) { - fz_drop_buffer(ctx, fzbuf); pdf_drop_obj(javascript); } fz_catch(ctx) @@ -324,7 +333,8 @@ void pdf_drop_js(pdf_js *js) void pdf_js_setup_event(pdf_js *js, pdf_obj *target) { - js->event.target = target; + if (js) + js->event.target = target; } void pdf_js_execute(pdf_js *js, char *code) -- cgit v1.2.3