0% found this document useful (0 votes)
15 views2 pages

Patch 1

This document shows code changes made to functions that get inherited values from a PDF object's parent objects. The updated functions avoid deep recursion by tracking the slowest moving parent object, rather than recursively calling themselves. They throw an error if the same parent object is reached twice, indicating a cycle in the parent relationships.

Uploaded by

khgrestaurantes
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views2 pages

Patch 1

This document shows code changes made to functions that get inherited values from a PDF object's parent objects. The updated functions avoid deep recursion by tracking the slowest moving parent object, rather than recursively calling themselves. They throw an error if the same parent object is reached twice, indicating a cycle in the parent relationships.

Uploaded by

khgrestaurantes
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

diff --git a/source/pdf/pdf-object.c b/source/pdf/pdf-object.

c
index 39662b00d..ab3c37227 100644
--- a/source/pdf/pdf-object.c
+++ b/source/pdf/pdf-object.c
@@ -3268,50 +3268,48 @@ int pdf_obj_refs(fz_context *ctx, pdf_obj *obj)

/* Convenience functions */

-static pdf_obj *
-pdf_dict_get_inheritable_imp(fz_context *ctx, pdf_obj *node, pdf_obj *key, int
depth, pdf_cycle_list *cycle_up)
-{
- pdf_cycle_list cycle;
- pdf_obj *val = pdf_dict_get(ctx, node, key);
- if (val)
- return val;
- if (pdf_cycle(ctx, &cycle, cycle_up, node))
- fz_throw(ctx, FZ_ERROR_GENERIC, "cycle in tree (parents)");
- if (depth > 100)
- fz_throw(ctx, FZ_ERROR_GENERIC, "too much recursion in tree
(parents)");
- node = pdf_dict_get(ctx, node, PDF_NAME(Parent));
- if (node)
- return pdf_dict_get_inheritable_imp(ctx, node, key, depth + 1, &cycle);
- return NULL;
-}
-
pdf_obj *
pdf_dict_get_inheritable(fz_context *ctx, pdf_obj *node, pdf_obj *key)
{
- return pdf_dict_get_inheritable_imp(ctx, node, key, 0, NULL);
-}
-
-static pdf_obj *
-pdf_dict_getp_inheritable_imp(fz_context *ctx, pdf_obj *node, const char *path,
int depth, pdf_cycle_list *cycle_up)
-{
- pdf_cycle_list cycle;
- pdf_obj *val = pdf_dict_getp(ctx, node, path);
- if (val)
- return val;
- if (pdf_cycle(ctx, &cycle, cycle_up, node))
- fz_throw(ctx, FZ_ERROR_GENERIC, "cycle in tree (parents)");
- if (depth > 100)
- fz_throw(ctx, FZ_ERROR_GENERIC, "too much recursion in tree
(parents)");
- node = pdf_dict_get(ctx, node, PDF_NAME(Parent));
- if (node)
- return pdf_dict_getp_inheritable_imp(ctx, node, path, depth + 1,
&cycle);
+ pdf_obj *slow = node;
+ int halfbeat = -10;
+ do {
+ pdf_obj* val = pdf_dict_get(ctx, node, key);
+ if (val)
+ return val;
+ node = pdf_dict_get(ctx, node, PDF_NAME(Parent));
+ if (node == slow) {
+ fz_throw(ctx, FZ_ERROR_GENERIC, "too much recursion in tree
(parents)");
+ }
+ ++halfbeat;
+ if (halfbeat >=2 && slow) {
+ slow = pdf_dict_get(ctx, slow, PDF_NAME(Parent));
+ halfbeat = 0;
+ }
+ } while (node);
return NULL;
}

pdf_obj *
pdf_dict_getp_inheritable(fz_context *ctx, pdf_obj *node, const char *path)
{
- return pdf_dict_getp_inheritable_imp(ctx, node, path, 0, NULL);
+ pdf_obj* slow = node;
+ int halfbeat = -10;
+ do {
+ pdf_obj* val = pdf_dict_getp(ctx, node, path);
+ if (val)
+ return val;
+ node = pdf_dict_get(ctx, node, PDF_NAME(Parent));
+ if (node == slow) {
+ fz_throw(ctx, FZ_ERROR_GENERIC, "too much recursion in tree
(parents)");
+ }
+ ++halfbeat;
+ if (halfbeat >= 2 && slow) {
+ slow = pdf_dict_get(ctx, slow, PDF_NAME(Parent));
+ halfbeat = 0;
+ }
+ } while (node);
+ return NULL;
}

void pdf_dict_put_bool(fz_context *ctx, pdf_obj *dict, pdf_obj *key, int x)

You might also like