summaryrefslogtreecommitdiff
path: root/source
diff options
context:
space:
mode:
authorSebastian Rasmussen <sebras@gmail.com>2016-09-22 19:25:18 +0800
committerSebastian Rasmussen <sebras@gmail.com>2016-09-22 19:26:42 +0800
commitfdf71862fe929b4560e9f632d775c50313d6ef02 (patch)
treefe1da74c61259bb381fe9f487cf47ae6ed26ec9a /source
parent19effcbc7a5c5ed948cf408e1f2d03b0ce1a1263 (diff)
downloadmupdf-fdf71862fe929b4560e9f632d775c50313d6ef02.tar.xz
Bug 697018: Avoid recursing infinitely on dicts in mutool info.
Diffstat (limited to 'source')
-rw-r--r--source/tools/pdfinfo.c96
1 files changed, 54 insertions, 42 deletions
diff --git a/source/tools/pdfinfo.c b/source/tools/pdfinfo.c
index 7d058b14..fd03db34 100644
--- a/source/tools/pdfinfo.c
+++ b/source/tools/pdfinfo.c
@@ -579,63 +579,75 @@ gatherresourceinfo(fz_context *ctx, globals *glo, int page, pdf_obj *rsrc, int s
int i;
pageref = pdf_lookup_page_obj(ctx, glo->doc, page-1);
-
if (!pageref)
fz_throw(ctx, FZ_ERROR_GENERIC, "cannot retrieve info from page %d", page);
- font = pdf_dict_get(ctx, rsrc, PDF_NAME_Font);
- if (show & FONTS && font)
- {
- int n;
+ /* stop on cyclic resource dependencies */
+ if (pdf_mark_obj(ctx, rsrc))
+ return;
- gatherfonts(ctx, glo, page, pageref, font);
- n = pdf_dict_len(ctx, font);
- for (i = 0; i < n; i++)
+ fz_try(ctx)
+ {
+ font = pdf_dict_get(ctx, rsrc, PDF_NAME_Font);
+ if (show & FONTS && font)
{
- pdf_obj *obj = pdf_dict_get_val(ctx, font, i);
+ int n;
- subrsrc = pdf_dict_get(ctx, obj, PDF_NAME_Resources);
- if (subrsrc && pdf_objcmp(ctx, rsrc, subrsrc))
- gatherresourceinfo(ctx, glo, page, subrsrc, show);
- }
- }
+ gatherfonts(ctx, glo, page, pageref, font);
+ n = pdf_dict_len(ctx, font);
+ for (i = 0; i < n; i++)
+ {
+ pdf_obj *obj = pdf_dict_get_val(ctx, font, i);
- xobj = pdf_dict_get(ctx, rsrc, PDF_NAME_XObject);
- if (show & XOBJS && xobj)
- {
- int n;
+ subrsrc = pdf_dict_get(ctx, obj, PDF_NAME_Resources);
+ if (subrsrc && pdf_objcmp(ctx, rsrc, subrsrc))
+ gatherresourceinfo(ctx, glo, page, subrsrc, show);
+ }
+ }
- gatherimages(ctx, glo, page, pageref, xobj);
- gatherforms(ctx, glo, page, pageref, xobj);
- gatherpsobjs(ctx, glo, page, pageref, xobj);
- n = pdf_dict_len(ctx, xobj);
- for (i = 0; i < n; i++)
+ xobj = pdf_dict_get(ctx, rsrc, PDF_NAME_XObject);
+ if (show & XOBJS && xobj)
{
- pdf_obj *obj = pdf_dict_get_val(ctx, xobj, i);
- subrsrc = pdf_dict_get(ctx, obj, PDF_NAME_Resources);
- if (subrsrc && pdf_objcmp(ctx, rsrc, subrsrc))
- gatherresourceinfo(ctx, glo, page, subrsrc, show);
+ int n;
+
+ gatherimages(ctx, glo, page, pageref, xobj);
+ gatherforms(ctx, glo, page, pageref, xobj);
+ gatherpsobjs(ctx, glo, page, pageref, xobj);
+ n = pdf_dict_len(ctx, xobj);
+ for (i = 0; i < n; i++)
+ {
+ pdf_obj *obj = pdf_dict_get_val(ctx, xobj, i);
+ subrsrc = pdf_dict_get(ctx, obj, PDF_NAME_Resources);
+ if (subrsrc && pdf_objcmp(ctx, rsrc, subrsrc))
+ gatherresourceinfo(ctx, glo, page, subrsrc, show);
+ }
}
- }
- shade = pdf_dict_get(ctx, rsrc, PDF_NAME_Shading);
- if (show & SHADINGS && shade)
- gathershadings(ctx, glo, page, pageref, shade);
+ shade = pdf_dict_get(ctx, rsrc, PDF_NAME_Shading);
+ if (show & SHADINGS && shade)
+ gathershadings(ctx, glo, page, pageref, shade);
- pattern = pdf_dict_get(ctx, rsrc, PDF_NAME_Pattern);
- if (show & PATTERNS && pattern)
- {
- int n;
- gatherpatterns(ctx, glo, page, pageref, pattern);
- n = pdf_dict_len(ctx, pattern);
- for (i = 0; i < n; i++)
+ pattern = pdf_dict_get(ctx, rsrc, PDF_NAME_Pattern);
+ if (show & PATTERNS && pattern)
{
- pdf_obj *obj = pdf_dict_get_val(ctx, pattern, i);
- subrsrc = pdf_dict_get(ctx, obj, PDF_NAME_Resources);
- if (subrsrc && pdf_objcmp(ctx, rsrc, subrsrc))
- gatherresourceinfo(ctx, glo, page, subrsrc, show);
+ int n;
+ gatherpatterns(ctx, glo, page, pageref, pattern);
+ n = pdf_dict_len(ctx, pattern);
+ for (i = 0; i < n; i++)
+ {
+ pdf_obj *obj = pdf_dict_get_val(ctx, pattern, i);
+ subrsrc = pdf_dict_get(ctx, obj, PDF_NAME_Resources);
+ if (subrsrc && pdf_objcmp(ctx, rsrc, subrsrc))
+ gatherresourceinfo(ctx, glo, page, subrsrc, show);
+ }
}
}
+ fz_always(ctx)
+ pdf_unmark_obj(ctx, rsrc);
+ fz_catch(ctx)
+ fz_rethrow(ctx);
+
+
}
static void