summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'pdf/pdf_array.c')
-rw-r--r--pdf/pdf_array.c31
1 files changed, 12 insertions, 19 deletions
diff --git a/pdf/pdf_array.c b/pdf/pdf_array.c
index 07a90812..5f269fe5 100644
--- a/pdf/pdf_array.c
+++ b/pdf/pdf_array.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 2018-2021 Artifex Software, Inc.
+/* Copyright (C) 2018-2022 Artifex Software, Inc.
All Rights Reserved.
This software is provided AS-IS with no warranty, either express or
@@ -53,7 +53,7 @@ int pdfi_array_alloc(pdf_context *ctx, uint64_t size, pdf_array **a)
/* Make a null object */
code = pdfi_object_alloc(ctx, PDF_NULL, 1, &n);
if (code < 0) {
- pdfi_countdown(*a);
+ pdfi_free_object((pdf_obj *)(*a));
*a = NULL;
return code;
}
@@ -121,7 +121,7 @@ int pdfi_array_from_stack(pdf_context *ctx, uint32_t indirect_num, uint32_t indi
/* Fetch object from array, resolving indirect reference if needed
* setref -- indicates whether to replace indirect ref with the object
*/
-static int pdfi_array_fetch(pdf_context *ctx, pdf_array *a, uint64_t index, pdf_obj **o, bool setref)
+int pdfi_array_fetch(pdf_context *ctx, pdf_array *a, uint64_t index, pdf_obj **o, bool setref, bool cache)
{
int code;
pdf_obj *obj;
@@ -139,7 +139,13 @@ static int pdfi_array_fetch(pdf_context *ctx, pdf_array *a, uint64_t index, pdf_
pdf_obj *o1 = NULL;
pdf_indirect_ref *r = (pdf_indirect_ref *)obj;
- code = pdfi_deref_loop_detect(ctx, r->ref_object_num, r->ref_generation_num, &o1);
+ if (r->ref_object_num == a->object_num)
+ return_error(gs_error_circular_reference);
+
+ if (cache)
+ code = pdfi_deref_loop_detect(ctx, r->ref_object_num, r->ref_generation_num, &o1);
+ else
+ code = pdfi_deref_loop_detect_nocache(ctx, r->ref_object_num, r->ref_generation_num, &o1);
if (code < 0)
return code;
@@ -154,19 +160,6 @@ static int pdfi_array_fetch(pdf_context *ctx, pdf_array *a, uint64_t index, pdf_
return 0;
}
-/* The object returned by pdfi_array_get has its reference count incremented by 1 to
- * indicate the reference now held by the caller, in **o.
- */
-int pdfi_array_get(pdf_context *ctx, pdf_array *a, uint64_t index, pdf_obj **o)
-{
- int code;
-
- code = pdfi_array_fetch(ctx, a, index, o, true);
- if (code < 0) return code;
-
- return 0;
-}
-
/* Get element from array without resolving PDF_INDIRECT dereferences.
* It looks to me like some usages need to do the checking themselves to
* avoid circular references? Can remove this if not really needed.
@@ -190,7 +183,7 @@ int pdfi_array_get_no_store_R(pdf_context *ctx, pdf_array *a, uint64_t index, pd
{
int code;
- code = pdfi_array_fetch(ctx, a, index, o, false);
+ code = pdfi_array_fetch(ctx, a, index, o, false, false);
if (code < 0) return code;
return 0;
@@ -267,7 +260,7 @@ bool pdfi_array_known(pdf_context *ctx, pdf_array *a, pdf_obj *o, int *index)
pdf_obj *val;
int code;
- code = pdfi_array_fetch(ctx, a, i, &val, true);
+ code = pdfi_array_fetch(ctx, a, i, &val, true, true);
if (code < 0)
continue;
if (val->object_num == o->object_num) {