summaryrefslogtreecommitdiff
path: root/pdf/pdf_form.c
diff options
context:
space:
mode:
authorRobin Watts <robin.watts@artifex.com>2012-06-22 13:26:35 +0100
committerRobin Watts <robin.watts@artifex.com>2012-06-22 16:42:09 +0100
commitb4157f3585c0f7a07305ac324e7ab9d47e7d04ae (patch)
treed993f31a9fb04e9b833ca042e2aa8088e393999c /pdf/pdf_form.c
parent34fc2fb23d9f0a9b2a68896e608ea149d8bc38e2 (diff)
downloadmupdf-b4157f3585c0f7a07305ac324e7ab9d47e7d04ae.tar.xz
Rework pdf_lexbuf to allow for dynamic parsing buffers.
Currently pdf_lexbufs use a static scratch buffer for parsing. In the main case this is 64K in size, but in other cases it can be just 256 bytes; this causes problems when parsing long strings. Even the 64K limit is an implementation limit of Acrobat, not an architectural limit of PDF. Change here to allow dynamic buffers. This means a slightly more complex setup and destruction for each buffer, but more importantly requires correct cleanup on errors. To avoid having to insert lots more try/catch clauses this commit includes various changes to the code so we reuse pdf_lexbufs where possible. This keeps the speed up.
Diffstat (limited to 'pdf/pdf_form.c')
-rw-r--r--pdf/pdf_form.c12
1 files changed, 6 insertions, 6 deletions
diff --git a/pdf/pdf_form.c b/pdf/pdf_form.c
index 45510aac..68db8327 100644
--- a/pdf/pdf_form.c
+++ b/pdf/pdf_form.c
@@ -293,8 +293,7 @@ static void parse_da(fz_context *ctx, char *da, da_info *di)
pdf_lexbuf lbuf;
fz_stream *str = fz_open_memory(ctx, (unsigned char *)da, strlen(da));
- memset(lbuf.scratch, 0, sizeof(lbuf.scratch));
- lbuf.size = sizeof(lbuf.scratch);
+ pdf_lexbuf_init(ctx, &lbuf, PDF_LEXBUF_SMALL);
fz_var(str);
fz_var(name);
@@ -347,6 +346,7 @@ static void parse_da(fz_context *ctx, char *da, da_info *di)
{
fz_free(ctx, name);
fz_close(str);
+ pdf_lexbuf_fin(&lbuf);
}
fz_catch(ctx)
{
@@ -852,8 +852,7 @@ static void update_marked_content(pdf_document *doc, pdf_xobject *form, fz_buffe
int len;
fz_buffer *newbuf = NULL;
- memset(lbuf.scratch, 0, sizeof(lbuf.scratch));
- lbuf.size = sizeof(lbuf.scratch);
+ pdf_lexbuf_init(ctx, &lbuf, PDF_LEXBUF_SMALL);
fz_var(str_outer);
fz_var(str_inner);
@@ -922,6 +921,7 @@ static void update_marked_content(pdf_document *doc, pdf_xobject *form, fz_buffe
fz_close(str_outer);
fz_close(str_inner);
fz_drop_buffer(ctx, newbuf);
+ pdf_lexbuf_fin(&lbuf);
}
fz_catch(ctx)
{
@@ -938,8 +938,7 @@ static int get_matrix(pdf_document *doc, pdf_xobject *form, int q, fz_matrix *mt
str = pdf_open_stream(doc, pdf_to_num(form->contents), pdf_to_gen(form->contents));
- memset(lbuf.scratch, 0, sizeof(lbuf.scratch));
- lbuf.size = sizeof(lbuf.scratch);
+ pdf_lexbuf_init(ctx, &lbuf, PDF_LEXBUF_SMALL);
fz_try(ctx)
{
@@ -1004,6 +1003,7 @@ static int get_matrix(pdf_document *doc, pdf_xobject *form, int q, fz_matrix *mt
fz_always(ctx)
{
fz_close(str);
+ pdf_lexbuf_fin(&lbuf);
}
fz_catch(ctx)
{