summaryrefslogtreecommitdiff
path: root/pdf
diff options
context:
space:
mode:
authorRobin Watts <robin.watts@artifex.com>2012-01-13 16:08:27 +0000
committerRobin Watts <robin.watts@artifex.com>2012-01-13 16:08:27 +0000
commitb203c82007a8f5e321e2e2b74b8b3ee58a425ba5 (patch)
tree5b47cdf049e060eb684b768f71f02021abccd23b /pdf
parentdc3854ce4db9b57746a163faf9c2451890cd5128 (diff)
downloadmupdf-b203c82007a8f5e321e2e2b74b8b3ee58a425ba5.tar.xz
Allow the interpreter gstate stack to grow.
Copes with files with many many gstates in; such as 'tikz-gtree' documents, according to Sumatra. Thanks to Zeniko for this.
Diffstat (limited to 'pdf')
-rw-r--r--pdf/pdf_interpret.c18
1 files changed, 13 insertions, 5 deletions
diff --git a/pdf/pdf_interpret.c b/pdf/pdf_interpret.c
index 0976912e..0cfcdfae 100644
--- a/pdf/pdf_interpret.c
+++ b/pdf/pdf_interpret.c
@@ -95,7 +95,8 @@ struct pdf_csi_s
/* graphics state */
fz_matrix top_ctm;
- pdf_gstate gstate[64];
+ pdf_gstate *gstate;
+ int gcap;
int gtop;
/* cookie support */
@@ -890,6 +891,9 @@ pdf_new_csi(pdf_xref *xref, fz_device *dev, fz_matrix ctm, char *event, fz_cooki
csi->text_mode = 0;
csi->accumulate = 1;
+ csi->gcap = 64;
+ csi->gstate = fz_malloc_array(ctx, csi->gcap, sizeof(pdf_gstate));
+
csi->top_ctm = ctm;
pdf_init_gstate(&csi->gstate[0], ctm);
csi->gtop = 0;
@@ -898,6 +902,7 @@ pdf_new_csi(pdf_xref *xref, fz_device *dev, fz_matrix ctm, char *event, fz_cooki
}
fz_catch(ctx)
{
+ fz_free_path(ctx, csi->path);
fz_free(ctx, csi);
fz_rethrow(ctx);
}
@@ -950,13 +955,14 @@ static void
pdf_gsave(pdf_csi *csi)
{
fz_context *ctx = csi->dev->ctx;
- pdf_gstate *gs = csi->gstate + csi->gtop;
+ pdf_gstate *gs;
- if (csi->gtop == nelem(csi->gstate) - 1)
+ if (csi->gtop == csi->gcap-1)
{
- fz_warn(ctx, "gstate overflow in content stream");
- return;
+ csi->gstate = fz_resize_array(ctx, csi->gstate, csi->gcap*2, sizeof(pdf_gstate));
+ csi->gcap *= 2;
}
+ gs = csi->gstate + csi->gtop;
memcpy(&csi->gstate[csi->gtop + 1], &csi->gstate[csi->gtop], sizeof(pdf_gstate));
@@ -1030,6 +1036,8 @@ pdf_free_csi(pdf_csi *csi)
pdf_clear_stack(csi);
+ fz_free(ctx, csi->gstate);
+
fz_free(ctx, csi);
}