diff options
author | Paul Gardiner <paul@glidos.net> | 2012-07-13 14:20:47 +0100 |
---|---|---|
committer | Paul Gardiner <paul@glidos.net> | 2012-07-17 12:15:03 +0100 |
commit | 4499536d9678608bf2f1da36e2768ad84ce9980b (patch) | |
tree | ee02884163254de6aafe92327402e1ea0b534fe2 /pdf/pdf_form.c | |
parent | 9742497a2a2ecbba332c2f9565ffd57cb69c5675 (diff) | |
download | mupdf-4499536d9678608bf2f1da36e2768ad84ce9980b.tar.xz |
Forms: protect agains recursion during internal field recalculation
Diffstat (limited to 'pdf/pdf_form.c')
-rw-r--r-- | pdf/pdf_form.c | 41 |
1 files changed, 29 insertions, 12 deletions
diff --git a/pdf/pdf_form.c b/pdf/pdf_form.c index 95603776..90b89d25 100644 --- a/pdf/pdf_form.c +++ b/pdf/pdf_form.c @@ -1716,27 +1716,44 @@ char *pdf_field_getValue(pdf_document *doc, pdf_obj *field) static void recalculate(pdf_document *doc) { - pdf_obj *co = pdf_dict_getp(doc->trailer, "Root/AcroForm/CO"); + fz_context *ctx = doc->ctx; + + if (doc->recalculating) + return; - if (co) + doc->recalculating = 1; + fz_try(ctx) { - int i, n = pdf_array_len(co); + pdf_obj *co = pdf_dict_getp(doc->trailer, "Root/AcroForm/CO"); - for (i = 0; i < n; i++) + if (co) { - pdf_obj *field = pdf_array_get(co, i); - pdf_obj *calc = pdf_dict_getp(field, "AA/C"); + int i, n = pdf_array_len(co); - if (calc) + for (i = 0; i < n; i++) { - execute_action(doc, field, calc); - /* A calculate action, updates event.value. We need - * to place the value in the field */ - update_text_field_value(doc->ctx, field, pdf_js_getEventValue(doc->js)); - pdf_field_mark_dirty(doc->ctx, field); + pdf_obj *field = pdf_array_get(co, i); + pdf_obj *calc = pdf_dict_getp(field, "AA/C"); + + if (calc) + { + execute_action(doc, field, calc); + /* A calculate action, updates event.value. We need + * to place the value in the field */ + update_text_field_value(doc->ctx, field, pdf_js_getEventValue(doc->js)); + pdf_field_mark_dirty(doc->ctx, field); + } } } } + fz_always(ctx) + { + doc->recalculating = 0; + } + fz_catch(ctx) + { + fz_rethrow(ctx); + } } void pdf_field_setValue(pdf_document *doc, pdf_obj *field, char *text) |