summaryrefslogtreecommitdiff
path: root/pdf
diff options
context:
space:
mode:
authorPaul Gardiner <paulg.artifex@glidos.net>2012-08-24 09:04:20 +0100
committerPaul Gardiner <paulg.artifex@glidos.net>2012-08-24 09:04:20 +0100
commit333d8c765d298b697ef8c29a1f8a192238b21b67 (patch)
tree4f59cc7e3d15bfb821e65b6e753b5a8aac017dea /pdf
parent46aa12efced7578b466b2c49bf8e2c512ebf0b49 (diff)
downloadmupdf-333d8c765d298b697ef8c29a1f8a192238b21b67.tar.xz
Forms: avoid javascript action execution when engine not available
This was necessary to avoid indirecting through a NULL pointer returned from pdf_js_get_event, but is a generally sensible restriction. Also separate the execution of the document-level javascript actions from the pdf_js contstructor, so that doc->js is set during those actions. Also add a missing const
Diffstat (limited to 'pdf')
-rw-r--r--pdf/mupdf-internal.h1
-rw-r--r--pdf/pdf_form.c8
-rw-r--r--pdf/pdf_js.c35
-rw-r--r--pdf/pdf_js_none.c4
-rw-r--r--pdf/pdf_jsimp_cpp.c2
-rw-r--r--pdf/pdf_xref.c1
6 files changed, 36 insertions, 15 deletions
diff --git a/pdf/mupdf-internal.h b/pdf/mupdf-internal.h
index fe1bf0ad..ec44a2f4 100644
--- a/pdf/mupdf-internal.h
+++ b/pdf/mupdf-internal.h
@@ -633,6 +633,7 @@ typedef struct pdf_js_event_s
pdf_js *pdf_new_js(pdf_document *doc);
void pdf_drop_js(pdf_js *js);
+void pdf_js_load_document_level(pdf_js *js);
void pdf_js_setup_event(pdf_js *js, pdf_js_event *e);
pdf_js_event *pdf_js_get_event(pdf_js *js);
void pdf_js_execute(pdf_js *js, char *code);
diff --git a/pdf/pdf_form.c b/pdf/pdf_form.c
index 18b45631..cb92956f 100644
--- a/pdf/pdf_form.c
+++ b/pdf/pdf_form.c
@@ -1558,7 +1558,7 @@ void pdf_update_appearance(pdf_document *doc, pdf_obj *obj)
case FZ_WIDGET_TYPE_TEXT:
{
pdf_obj *formatting = pdf_dict_getp(obj, "AA/F");
- if (formatting)
+ if (formatting && doc->js)
{
/* Apply formatting */
pdf_js_event e;
@@ -1863,7 +1863,7 @@ static void recalculate(pdf_document *doc)
{
pdf_obj *co = pdf_dict_getp(doc->trailer, "Root/AcroForm/CO");
- if (co)
+ if (co && doc->js)
{
int i, n = pdf_array_len(co);
@@ -1902,7 +1902,7 @@ int pdf_field_setValue(pdf_document *doc, pdf_obj *field, char *text)
{
pdf_obj *v = pdf_dict_getp(field, "AA/V");
- if (v)
+ if (v && doc->js)
{
pdf_js_event e;
@@ -2116,7 +2116,7 @@ static int run_keystroke(pdf_document *doc, pdf_obj *field, char **text)
{
pdf_obj *k = pdf_dict_getp(field, "AA/K");
- if (k)
+ if (k && doc->js)
{
pdf_js_event e;
diff --git a/pdf/pdf_js.c b/pdf/pdf_js.c
index dd801db7..0059ca4f 100644
--- a/pdf/pdf_js.c
+++ b/pdf/pdf_js.c
@@ -244,7 +244,7 @@ static char *utf8_to_pdf(fz_context *ctx, char *utf8)
{
char *pdf = fz_malloc(ctx, strlen(utf8)+1);
int i = 0;
- char c;
+ unsigned char c;
while ((c = *utf8) != 0)
{
@@ -374,16 +374,12 @@ pdf_js *pdf_new_js(pdf_document *doc)
{
fz_context *ctx = doc->ctx;
pdf_js *js = NULL;
- pdf_obj *javascript = NULL;
- char *codebuf = NULL;
fz_var(js);
- fz_var(javascript);
- fz_var(codebuf);
fz_try(ctx)
{
- int len, i;
pdf_obj *root, *acroform;
+
js = fz_malloc_struct(ctx, pdf_js);
js->doc = doc;
@@ -399,6 +395,28 @@ pdf_js *pdf_new_js(pdf_document *doc)
declare_dom(js);
preload_helpers(js);
+ }
+ fz_catch(ctx)
+ {
+ pdf_drop_js(js);
+ js = NULL;
+ }
+
+ return js;
+}
+
+void pdf_js_load_document_level(pdf_js *js)
+{
+ pdf_document *doc = js->doc;
+ fz_context *ctx = doc->ctx;
+ pdf_obj *javascript = NULL;
+ char *codebuf = NULL;
+
+ fz_var(javascript);
+ fz_var(codebuf);
+ fz_try(ctx)
+ {
+ int len, i;
javascript = pdf_load_name_tree(doc, "JavaScript");
len = pdf_dict_len(javascript);
@@ -431,11 +449,8 @@ pdf_js *pdf_new_js(pdf_document *doc)
}
fz_catch(ctx)
{
- pdf_drop_js(js);
- js = NULL;
+ fz_rethrow(ctx);
}
-
- return js;
}
void pdf_drop_js(pdf_js *js)
diff --git a/pdf/pdf_js_none.c b/pdf/pdf_js_none.c
index 6632db5b..310f1a81 100644
--- a/pdf/pdf_js_none.c
+++ b/pdf/pdf_js_none.c
@@ -27,6 +27,10 @@ pdf_js *pdf_new_js(pdf_document *doc)
return js;
}
+void pdf_js_load_document_level(pdf_js *js)
+{
+}
+
void pdf_drop_js(pdf_js *js)
{
if (js)
diff --git a/pdf/pdf_jsimp_cpp.c b/pdf/pdf_jsimp_cpp.c
index aa9539cf..b1767700 100644
--- a/pdf/pdf_jsimp_cpp.c
+++ b/pdf/pdf_jsimp_cpp.c
@@ -106,7 +106,7 @@ char *pdf_jsimp_toString(pdf_jsimp *imp, pdf_jsimp_obj *obj)
pdf_jsimp_obj *pdf_jsimp_fromNumber(pdf_jsimp *imp, double num)
{
pdf_jsimp_obj *obj = NULL;
- char *err = pdf_jsimp_fromNumber_cpp(imp, num, &obj);
+ const char *err = pdf_jsimp_fromNumber_cpp(imp, num, &obj);
if (err != NULL)
fz_throw(pdf_jsimp_ctx_cpp(imp), "%s", err);
diff --git a/pdf/pdf_xref.c b/pdf/pdf_xref.c
index 7c14265d..a8b8ab43 100644
--- a/pdf/pdf_xref.c
+++ b/pdf/pdf_xref.c
@@ -782,6 +782,7 @@ pdf_init_document(pdf_document *xref)
}
}
xref->js = pdf_new_js(xref);
+ pdf_js_load_document_level(xref->js);
}
fz_catch(ctx)
{