Debian Codegraph @

pdf/pdf_loop_detect.h

raw
1 /* Copyright (C) 2018-2023 Artifex Software, Inc.
2 All Rights Reserved.
3
4 This software is provided AS-IS with no warranty, either express or
5 implied.
6
7 This software is distributed under license and may not be copied,
8 modified or distributed except as expressly authorized under the terms
9 of the license contained in the file LICENSE in this distribution.
10
11 Refer to licensing information at http://www.artifex.com or contact
12 Artifex Software, Inc., 39 Mesa Street, Suite 108A, San Francisco,
13 CA 94129, USA, for further information.
14 */
15
16 /* We handle circular references (loops) in the Pages tree or Resources as follows;
17 * When we want to check for loops, we start up the loop detector
18 * This stores an array of object numbers in the context
19 * Every time we dereference an object, if the loop detector is present, pdf_dereference_object
20 * checks to see if the object its asked to dereference is in the array. If it is,
21 * we return an error. Ohterwise, when we finish creating the dereferenced object,
22 * we add its number to the array.
23 * Now its possible for the same object to be referenced in different branches of a tree
24 * and this simple detection would cause a problem. So we define a 'mark' in the array.
25 * We use object number 0 for this since that is, by definition, always free.
26 * When we start checking a branch, we 'mark' the array, and when we've finished the branch
27 * we 'cleartomark'. Then if we find we are dereferencing the same object again we won't
28 * produce a spurious error.
29 */
30 #ifndef PDF_LOOP_DETECTOR
31 #define PDF_LOOP_DETECTOR
32
33 int pdfi_loop_detector_add_object(pdf_context *ctx, uint64_t object);
34 bool pdfi_loop_detector_check_object(pdf_context *ctx, uint64_t object);
35 int pdfi_loop_detector_mark(pdf_context *ctx);
36 int pdfi_loop_detector_cleartomark(pdf_context *ctx);
37
38 #endif