/src/ghostpdl/pdf/pdf_fontps.h
Line | Count | Source (jump to first uncovered line) |
1 | | /* Copyright (C) 2020-2024 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 | | /* common code for Postscript-type font handling */ |
17 | | |
18 | | #ifndef PDF_FONTPS_H |
19 | | #define PDF_FONTPS_H |
20 | | |
21 | | #include "gxfont1.h" /* for gs_font_type1_s */ |
22 | | |
23 | | typedef enum |
24 | | { |
25 | | PDF_PS_OBJ_NULL, |
26 | | PDF_PS_OBJ_INTEGER, |
27 | | PDF_PS_OBJ_FLOAT, |
28 | | PDF_PS_OBJ_STRING, |
29 | | PDF_PS_OBJ_NAME, |
30 | | PDF_PS_OBJ_ARRAY, |
31 | | PDF_PS_OBJ_MARK, |
32 | | PDF_PS_OBJ_TRUE, |
33 | | PDF_PS_OBJ_FALSE, |
34 | | PDF_PS_OBJ_ARR_MARK, |
35 | | PDF_PS_OBJ_DICT_MARK, |
36 | | PDF_PS_OBJ_STACK_TOP, |
37 | | PDF_PS_OBJ_STACK_BOTTOM |
38 | | } pdf_ps_obj_type; |
39 | | |
40 | | typedef struct pdf_ps_stack_object_s pdf_ps_stack_object_t; |
41 | | |
42 | | struct pdf_ps_stack_object_s |
43 | | { |
44 | | pdf_ps_obj_type type; |
45 | | uint32_t size; |
46 | | union v { |
47 | | int i; |
48 | | float f; |
49 | | byte *string; |
50 | | byte *name; |
51 | | pdf_ps_stack_object_t *arr; |
52 | | } val; |
53 | | }; |
54 | | |
55 | | /* The maximum size of a set of a single "block" is 100 "items" |
56 | | the worst of which is cid ranges which take three objects |
57 | | (lo character code, hi character, low cid) for each item. |
58 | | Thus we need an available stack depth of up to 300 objects. |
59 | | Allowing for possible bad behaviour, 350 seems like a safe |
60 | | size. There are stack limit guard entries at the top and bottom |
61 | | */ |
62 | | typedef struct pdf_ps_ctx_s pdf_ps_ctx_t; |
63 | | |
64 | 2.70M | #define PDF_PS_OPER_NAME_AND_LEN(s) (const byte *)s, sizeof(s) - 1 |
65 | | |
66 | | typedef struct { |
67 | | const byte *opname; |
68 | | const int opnamelen; |
69 | | int (*oper)(gs_memory_t *mem, pdf_ps_ctx_t *stack, byte *buf, byte *bufend); |
70 | | } pdf_ps_oper_list_t; |
71 | | |
72 | 641k | #define PDF_PS_STACK_SIZE 360 |
73 | 7.22M | #define PDF_PS_STACK_GUARDS 1 |
74 | 19.3k | #define PDF_PS_STACK_GROW_SIZE PDF_PS_STACK_SIZE + 2 * PDF_PS_STACK_GUARDS |
75 | 331k | #define PDF_PS_STACK_MAX PDF_PS_STACK_SIZE * 16 /* Arbitrary value.... */ |
76 | | struct pdf_ps_ctx_s |
77 | | { |
78 | | pdf_context *pdfi_ctx; |
79 | | pdf_ps_stack_object_t *cur; /* current top of the stack */ |
80 | | pdf_ps_stack_object_t *toplim; /* the upper limit of the stack */ |
81 | | pdf_ps_stack_object_t *stack; |
82 | | pdf_ps_oper_list_t *ops; |
83 | | void *client_data; |
84 | | }; |
85 | | |
86 | | |
87 | | typedef struct { |
88 | | union { |
89 | | pdf_font_type1 t1; |
90 | | pdf_cidfont_type0 cidt0; |
91 | | } u; |
92 | | union { |
93 | | gs_font_type1 gst1; |
94 | | } gsu; |
95 | | } ps_font_interp_private; |
96 | | |
97 | | |
98 | | int pdfi_read_ps_font(pdf_context *ctx, pdf_dict *font_dict, byte *fbuf, int fbuflen, ps_font_interp_private *ps_font_priv); |
99 | | |
100 | | int pdfi_pscript_stack_init(pdf_context *pdfi_ctx, pdf_ps_oper_list_t *ops, void *client_data, pdf_ps_ctx_t *s); |
101 | | void pdfi_pscript_stack_finit(pdf_ps_ctx_t *s); |
102 | | int pdfi_pscript_interpret(pdf_ps_ctx_t *cs, byte *pspdfbuf, int64_t buflen); |
103 | | |
104 | | /* Begin default operator functions */ |
105 | | int ps_pdf_null_oper_func(gs_memory_t *mem, pdf_ps_ctx_t *stack, byte *buf, byte *bufend); |
106 | | int clear_stack_oper_func(gs_memory_t *mem, pdf_ps_ctx_t *s, byte *buf, byte *bufend); |
107 | | int pdf_ps_pop_oper_func(gs_memory_t *mem, pdf_ps_ctx_t *s, byte *buf, byte *bufend); |
108 | | int pdf_ps_pop_and_pushmark_func(gs_memory_t *mem, pdf_ps_ctx_t *stack, byte *buf, byte *bufend); |
109 | | /* End default operator functions */ |
110 | | |
111 | | static inline void pdf_ps_make_null(pdf_ps_stack_object_t *obj) |
112 | 216M | { |
113 | 216M | obj->type = PDF_PS_OBJ_NULL; |
114 | 216M | obj->size = 0; |
115 | 216M | memset(&obj->val, 0x00, sizeof(obj->val)); |
116 | 216M | } Unexecuted instantiation: pdf_font1.c:pdf_ps_make_null Unexecuted instantiation: pdf_font1C.c:pdf_ps_make_null pdf_fontps.c:pdf_ps_make_null Line | Count | Source | 112 | 173M | { | 113 | 173M | obj->type = PDF_PS_OBJ_NULL; | 114 | 173M | obj->size = 0; | 115 | 173M | memset(&obj->val, 0x00, sizeof(obj->val)); | 116 | 173M | } |
pdf_cmap.c:pdf_ps_make_null Line | Count | Source | 112 | 42.4M | { | 113 | 42.4M | obj->type = PDF_PS_OBJ_NULL; | 114 | 42.4M | obj->size = 0; | 115 | 42.4M | memset(&obj->val, 0x00, sizeof(obj->val)); | 116 | 42.4M | } |
|
117 | | static inline void pdf_ps_make_array_mark(pdf_ps_stack_object_t *obj) |
118 | 2.16M | { |
119 | 2.16M | obj->type = PDF_PS_OBJ_ARR_MARK; |
120 | 2.16M | obj->size = 0; |
121 | 2.16M | } Unexecuted instantiation: pdf_font1.c:pdf_ps_make_array_mark Unexecuted instantiation: pdf_font1C.c:pdf_ps_make_array_mark pdf_fontps.c:pdf_ps_make_array_mark Line | Count | Source | 118 | 2.16M | { | 119 | 2.16M | obj->type = PDF_PS_OBJ_ARR_MARK; | 120 | 2.16M | obj->size = 0; | 121 | 2.16M | } |
Unexecuted instantiation: pdf_cmap.c:pdf_ps_make_array_mark |
122 | | static inline void pdf_ps_make_dict_mark(pdf_ps_stack_object_t *obj) |
123 | 253k | { |
124 | 253k | obj->type = PDF_PS_OBJ_DICT_MARK; |
125 | 253k | obj->size = 0; |
126 | 253k | } Unexecuted instantiation: pdf_font1.c:pdf_ps_make_dict_mark Unexecuted instantiation: pdf_font1C.c:pdf_ps_make_dict_mark pdf_fontps.c:pdf_ps_make_dict_mark Line | Count | Source | 123 | 253k | { | 124 | 253k | obj->type = PDF_PS_OBJ_DICT_MARK; | 125 | 253k | obj->size = 0; | 126 | 253k | } |
Unexecuted instantiation: pdf_cmap.c:pdf_ps_make_dict_mark |
127 | | static inline void pdf_ps_make_mark(pdf_ps_stack_object_t *obj) |
128 | 277k | { |
129 | 277k | obj->type = PDF_PS_OBJ_MARK; |
130 | 277k | obj->size = 0; |
131 | 277k | } Unexecuted instantiation: pdf_font1.c:pdf_ps_make_mark Unexecuted instantiation: pdf_font1C.c:pdf_ps_make_mark pdf_fontps.c:pdf_ps_make_mark Line | Count | Source | 128 | 277k | { | 129 | 277k | obj->type = PDF_PS_OBJ_MARK; | 130 | 277k | obj->size = 0; | 131 | 277k | } |
Unexecuted instantiation: pdf_cmap.c:pdf_ps_make_mark |
132 | | static inline void pdf_ps_make_int(pdf_ps_stack_object_t *obj, int val) |
133 | 68.9M | { |
134 | 68.9M | obj->type = PDF_PS_OBJ_INTEGER; |
135 | 68.9M | obj->size = 0; |
136 | 68.9M | obj->val.i = val; |
137 | 68.9M | } Unexecuted instantiation: pdf_font1.c:pdf_ps_make_int Unexecuted instantiation: pdf_font1C.c:pdf_ps_make_int pdf_fontps.c:pdf_ps_make_int Line | Count | Source | 133 | 67.0M | { | 134 | 67.0M | obj->type = PDF_PS_OBJ_INTEGER; | 135 | 67.0M | obj->size = 0; | 136 | 67.0M | obj->val.i = val; | 137 | 67.0M | } |
pdf_cmap.c:pdf_ps_make_int Line | Count | Source | 133 | 1.94M | { | 134 | 1.94M | obj->type = PDF_PS_OBJ_INTEGER; | 135 | 1.94M | obj->size = 0; | 136 | 1.94M | obj->val.i = val; | 137 | 1.94M | } |
|
138 | | static inline void pdf_ps_make_float(pdf_ps_stack_object_t *obj, float fval) |
139 | 532k | { |
140 | 532k | obj->type = PDF_PS_OBJ_FLOAT; |
141 | 532k | obj->size = 0; |
142 | 532k | obj->val.f = fval; |
143 | 532k | } Unexecuted instantiation: pdf_font1.c:pdf_ps_make_float Unexecuted instantiation: pdf_font1C.c:pdf_ps_make_float pdf_fontps.c:pdf_ps_make_float Line | Count | Source | 139 | 532k | { | 140 | 532k | obj->type = PDF_PS_OBJ_FLOAT; | 141 | 532k | obj->size = 0; | 142 | 532k | obj->val.f = fval; | 143 | 532k | } |
Unexecuted instantiation: pdf_cmap.c:pdf_ps_make_float |
144 | | static inline void pdf_ps_make_string(pdf_ps_stack_object_t *obj, byte *str, uint32_t len) |
145 | 29.5M | { |
146 | 29.5M | obj->type = PDF_PS_OBJ_STRING; |
147 | 29.5M | obj->size = len; |
148 | 29.5M | obj->val.string = str; |
149 | 29.5M | } Unexecuted instantiation: pdf_font1.c:pdf_ps_make_string Unexecuted instantiation: pdf_font1C.c:pdf_ps_make_string pdf_fontps.c:pdf_ps_make_string Line | Count | Source | 145 | 29.5M | { | 146 | 29.5M | obj->type = PDF_PS_OBJ_STRING; | 147 | 29.5M | obj->size = len; | 148 | 29.5M | obj->val.string = str; | 149 | 29.5M | } |
Unexecuted instantiation: pdf_cmap.c:pdf_ps_make_string |
150 | | static inline void pdf_ps_make_name(pdf_ps_stack_object_t *obj, byte *nm, uint32_t len) |
151 | 49.1M | { |
152 | 49.1M | obj->type = PDF_PS_OBJ_NAME; |
153 | 49.1M | obj->size = len; |
154 | 49.1M | obj->val.name = nm; |
155 | 49.1M | } Unexecuted instantiation: pdf_font1.c:pdf_ps_make_name Unexecuted instantiation: pdf_font1C.c:pdf_ps_make_name pdf_fontps.c:pdf_ps_make_name Line | Count | Source | 151 | 49.1M | { | 152 | 49.1M | obj->type = PDF_PS_OBJ_NAME; | 153 | 49.1M | obj->size = len; | 154 | 49.1M | obj->val.name = nm; | 155 | 49.1M | } |
Unexecuted instantiation: pdf_cmap.c:pdf_ps_make_name |
156 | | static inline void pdf_ps_make_array(pdf_ps_stack_object_t *obj, pdf_ps_stack_object_t *obj2, uint32_t len) |
157 | 2.61M | { |
158 | 2.61M | obj->type = PDF_PS_OBJ_ARRAY; |
159 | 2.61M | obj->size = len; |
160 | 2.61M | obj->val.arr = obj2; |
161 | 2.61M | } Unexecuted instantiation: pdf_font1.c:pdf_ps_make_array Unexecuted instantiation: pdf_font1C.c:pdf_ps_make_array pdf_fontps.c:pdf_ps_make_array Line | Count | Source | 157 | 2.17M | { | 158 | 2.17M | obj->type = PDF_PS_OBJ_ARRAY; | 159 | 2.17M | obj->size = len; | 160 | 2.17M | obj->val.arr = obj2; | 161 | 2.17M | } |
pdf_cmap.c:pdf_ps_make_array Line | Count | Source | 157 | 441k | { | 158 | 441k | obj->type = PDF_PS_OBJ_ARRAY; | 159 | 441k | obj->size = len; | 160 | 441k | obj->val.arr = obj2; | 161 | 441k | } |
|
162 | | static inline void pdf_ps_make_boolean(pdf_ps_stack_object_t *obj, bool b) |
163 | 127k | { |
164 | 127k | obj->type = b ? PDF_PS_OBJ_TRUE : PDF_PS_OBJ_FALSE; |
165 | 127k | obj->size = 0; |
166 | 127k | } Unexecuted instantiation: pdf_font1.c:pdf_ps_make_boolean Unexecuted instantiation: pdf_font1C.c:pdf_ps_make_boolean pdf_fontps.c:pdf_ps_make_boolean Line | Count | Source | 163 | 127k | { | 164 | 127k | obj->type = b ? PDF_PS_OBJ_TRUE : PDF_PS_OBJ_FALSE; | 165 | 127k | obj->size = 0; | 166 | 127k | } |
Unexecuted instantiation: pdf_cmap.c:pdf_ps_make_boolean |
167 | | |
168 | | static inline int pdf_ps_obj_has_type(pdf_ps_stack_object_t *o, pdf_ps_obj_type t) |
169 | 890M | { |
170 | 890M | return o->type == t; |
171 | 890M | } Unexecuted instantiation: pdf_font1.c:pdf_ps_obj_has_type Unexecuted instantiation: pdf_font1C.c:pdf_ps_obj_has_type pdf_fontps.c:pdf_ps_obj_has_type Line | Count | Source | 169 | 720M | { | 170 | 720M | return o->type == t; | 171 | 720M | } |
pdf_cmap.c:pdf_ps_obj_has_type Line | Count | Source | 169 | 169M | { | 170 | 169M | return o->type == t; | 171 | 169M | } |
|
172 | | |
173 | | static inline uint32_t pdf_ps_obj_size(pdf_ps_stack_object_t *o) |
174 | 34.4M | { |
175 | 34.4M | uint32_t s = 0; |
176 | 34.4M | if (o->type == PDF_PS_OBJ_ARRAY || o->type == PDF_PS_OBJ_NAME || o->type == PDF_PS_OBJ_STRING) { |
177 | 34.4M | s = o->size; |
178 | 34.4M | } |
179 | 34.4M | return s; |
180 | 34.4M | } Unexecuted instantiation: pdf_font1.c:pdf_ps_obj_size Unexecuted instantiation: pdf_font1C.c:pdf_ps_obj_size Unexecuted instantiation: pdf_fontps.c:pdf_ps_obj_size pdf_cmap.c:pdf_ps_obj_size Line | Count | Source | 174 | 34.4M | { | 175 | 34.4M | uint32_t s = 0; | 176 | 34.4M | if (o->type == PDF_PS_OBJ_ARRAY || o->type == PDF_PS_OBJ_NAME || o->type == PDF_PS_OBJ_STRING) { | 177 | 34.4M | s = o->size; | 178 | 34.4M | } | 179 | 34.4M | return s; | 180 | 34.4M | } |
|
181 | | |
182 | | /* The stack can grow, but doesn't shrink, just gets destroyed |
183 | | when we're done interpreting |
184 | | */ |
185 | | static inline int pdf_ps_stack_push(pdf_ps_ctx_t *s) |
186 | 147M | { |
187 | | /* Extending the stack pretty inefficient, but it shouldn't happen often |
188 | | for valid files |
189 | | */ |
190 | 147M | if (s->cur + 1 >= s->toplim - 1) { |
191 | 19.3k | int i, currsize = s->toplim - s->stack; |
192 | 19.3k | int newsize = currsize + PDF_PS_STACK_GROW_SIZE; |
193 | 19.3k | int newsizebytes = newsize * sizeof(pdf_ps_stack_object_t); |
194 | 19.3k | pdf_ps_stack_object_t *nstack; |
195 | | |
196 | 19.3k | if (newsize < PDF_PS_STACK_MAX) { |
197 | 18.0k | nstack = (pdf_ps_stack_object_t *)gs_alloc_bytes(s->pdfi_ctx->memory, newsizebytes, "pdf_ps_stack_push(nstack)"); |
198 | 18.0k | if (nstack != NULL) { |
199 | 18.0k | memcpy(nstack, s->stack, (currsize - 1) * sizeof(pdf_ps_stack_object_t)); |
200 | | |
201 | 36.1k | for (i = 0; i < PDF_PS_STACK_GUARDS; i++) |
202 | 18.0k | nstack[newsize - PDF_PS_STACK_GUARDS + i].type = PDF_PS_OBJ_STACK_TOP; |
203 | | |
204 | 6.56M | for (i = currsize - 1; i < newsize - PDF_PS_STACK_GUARDS; i++) { |
205 | 6.55M | pdf_ps_make_null(&(nstack[i])); |
206 | 6.55M | } |
207 | | |
208 | 18.0k | gs_free_object(s->pdfi_ctx->memory, s->stack, "pdf_ps_stack_push(s->stack)"); |
209 | 18.0k | s->stack = nstack; |
210 | 18.0k | s->cur = s->stack + currsize - 2; |
211 | 18.0k | s->toplim = s->stack + newsize; |
212 | 18.0k | } |
213 | 0 | else { |
214 | 0 | return_error(gs_error_VMerror); |
215 | 0 | } |
216 | 18.0k | } |
217 | 1.24k | else { |
218 | 1.24k | return_error(gs_error_stackoverflow); |
219 | 1.24k | } |
220 | 19.3k | } |
221 | 147M | s->cur++; |
222 | 147M | if (pdf_ps_obj_has_type(s->cur, PDF_PS_OBJ_STACK_TOP)) |
223 | 0 | return_error(gs_error_pdf_stackoverflow); |
224 | 147M | if (pdf_ps_obj_has_type(s->cur, PDF_PS_OBJ_STACK_BOTTOM)) |
225 | 0 | return_error(gs_error_stackunderflow); |
226 | 147M | return 0; |
227 | 147M | } Unexecuted instantiation: pdf_font1.c:pdf_ps_stack_push Unexecuted instantiation: pdf_font1C.c:pdf_ps_stack_push pdf_fontps.c:pdf_ps_stack_push Line | Count | Source | 186 | 147M | { | 187 | | /* Extending the stack pretty inefficient, but it shouldn't happen often | 188 | | for valid files | 189 | | */ | 190 | 147M | if (s->cur + 1 >= s->toplim - 1) { | 191 | 19.3k | int i, currsize = s->toplim - s->stack; | 192 | 19.3k | int newsize = currsize + PDF_PS_STACK_GROW_SIZE; | 193 | 19.3k | int newsizebytes = newsize * sizeof(pdf_ps_stack_object_t); | 194 | 19.3k | pdf_ps_stack_object_t *nstack; | 195 | | | 196 | 19.3k | if (newsize < PDF_PS_STACK_MAX) { | 197 | 18.0k | nstack = (pdf_ps_stack_object_t *)gs_alloc_bytes(s->pdfi_ctx->memory, newsizebytes, "pdf_ps_stack_push(nstack)"); | 198 | 18.0k | if (nstack != NULL) { | 199 | 18.0k | memcpy(nstack, s->stack, (currsize - 1) * sizeof(pdf_ps_stack_object_t)); | 200 | | | 201 | 36.1k | for (i = 0; i < PDF_PS_STACK_GUARDS; i++) | 202 | 18.0k | nstack[newsize - PDF_PS_STACK_GUARDS + i].type = PDF_PS_OBJ_STACK_TOP; | 203 | | | 204 | 6.56M | for (i = currsize - 1; i < newsize - PDF_PS_STACK_GUARDS; i++) { | 205 | 6.55M | pdf_ps_make_null(&(nstack[i])); | 206 | 6.55M | } | 207 | | | 208 | 18.0k | gs_free_object(s->pdfi_ctx->memory, s->stack, "pdf_ps_stack_push(s->stack)"); | 209 | 18.0k | s->stack = nstack; | 210 | 18.0k | s->cur = s->stack + currsize - 2; | 211 | 18.0k | s->toplim = s->stack + newsize; | 212 | 18.0k | } | 213 | 0 | else { | 214 | 0 | return_error(gs_error_VMerror); | 215 | 0 | } | 216 | 18.0k | } | 217 | 1.24k | else { | 218 | 1.24k | return_error(gs_error_stackoverflow); | 219 | 1.24k | } | 220 | 19.3k | } | 221 | 147M | s->cur++; | 222 | 147M | if (pdf_ps_obj_has_type(s->cur, PDF_PS_OBJ_STACK_TOP)) | 223 | 0 | return_error(gs_error_pdf_stackoverflow); | 224 | 147M | if (pdf_ps_obj_has_type(s->cur, PDF_PS_OBJ_STACK_BOTTOM)) | 225 | 0 | return_error(gs_error_stackunderflow); | 226 | 147M | return 0; | 227 | 147M | } |
Unexecuted instantiation: pdf_cmap.c:pdf_ps_stack_push |
228 | | |
229 | | static inline void pdf_ps_free_array_contents(pdf_ps_ctx_t *s, pdf_ps_stack_object_t *o) |
230 | 2.61M | { |
231 | 2.61M | int i; |
232 | 11.3M | for (i = 0; i < o->size; i++) { |
233 | 8.70M | if (pdf_ps_obj_has_type(&o->val.arr[i], PDF_PS_OBJ_ARRAY)) { |
234 | 991k | pdf_ps_stack_object_t *po = o->val.arr[i].val.arr; |
235 | 991k | pdf_ps_free_array_contents(s, &o->val.arr[i]); |
236 | 991k | gs_free_object(s->pdfi_ctx->memory, po, "pdf_ps_free_array_contents"); |
237 | 991k | } |
238 | 8.70M | pdf_ps_make_null(&o->val.arr[i]); |
239 | 8.70M | } |
240 | 2.61M | } Unexecuted instantiation: pdf_font1.c:pdf_ps_free_array_contents Unexecuted instantiation: pdf_font1C.c:pdf_ps_free_array_contents pdf_fontps.c:pdf_ps_free_array_contents Line | Count | Source | 230 | 2.12M | { | 231 | 2.12M | int i; | 232 | 10.1M | for (i = 0; i < o->size; i++) { | 233 | 7.99M | if (pdf_ps_obj_has_type(&o->val.arr[i], PDF_PS_OBJ_ARRAY)) { | 234 | 991k | pdf_ps_stack_object_t *po = o->val.arr[i].val.arr; | 235 | 991k | pdf_ps_free_array_contents(s, &o->val.arr[i]); | 236 | 991k | gs_free_object(s->pdfi_ctx->memory, po, "pdf_ps_free_array_contents"); | 237 | 991k | } | 238 | 7.99M | pdf_ps_make_null(&o->val.arr[i]); | 239 | 7.99M | } | 240 | 2.12M | } |
pdf_cmap.c:pdf_ps_free_array_contents Line | Count | Source | 230 | 486k | { | 231 | 486k | int i; | 232 | 1.19M | for (i = 0; i < o->size; i++) { | 233 | 711k | if (pdf_ps_obj_has_type(&o->val.arr[i], PDF_PS_OBJ_ARRAY)) { | 234 | 37 | pdf_ps_stack_object_t *po = o->val.arr[i].val.arr; | 235 | 37 | pdf_ps_free_array_contents(s, &o->val.arr[i]); | 236 | 37 | gs_free_object(s->pdfi_ctx->memory, po, "pdf_ps_free_array_contents"); | 237 | 37 | } | 238 | 711k | pdf_ps_make_null(&o->val.arr[i]); | 239 | 711k | } | 240 | 486k | } |
|
241 | | |
242 | | static inline int pdf_ps_stack_pop(pdf_ps_ctx_t *s, unsigned int n) |
243 | 54.3M | { |
244 | 54.3M | int n2 = n > s->cur - &(s->stack[0]) ? s->cur - &(s->stack[0]) : n; |
245 | 202M | while(n2--) { |
246 | | /* We only have one dimensional arrays to worry about */ |
247 | 147M | if (pdf_ps_obj_has_type(s->cur, PDF_PS_OBJ_ARRAY)) { |
248 | 1.62M | pdf_ps_free_array_contents(s, s->cur); |
249 | 1.62M | gs_free_object(s->pdfi_ctx->memory, s->cur->val.arr, "pdf_ps_stack_pop(s->cur->val.arr)"); |
250 | 1.62M | } |
251 | 147M | pdf_ps_make_null(s->cur); |
252 | 147M | s->cur--; |
253 | 147M | if (pdf_ps_obj_has_type(s->cur, PDF_PS_OBJ_STACK_TOP)) |
254 | 0 | return_error(gs_error_pdf_stackoverflow); |
255 | 147M | if (pdf_ps_obj_has_type(s->cur, PDF_PS_OBJ_STACK_BOTTOM)) |
256 | 3.30k | return_error(gs_error_stackunderflow); |
257 | 147M | } |
258 | 54.3M | return 0; |
259 | 54.3M | } Unexecuted instantiation: pdf_font1.c:pdf_ps_stack_pop Unexecuted instantiation: pdf_font1C.c:pdf_ps_stack_pop pdf_fontps.c:pdf_ps_stack_pop Line | Count | Source | 243 | 53.5M | { | 244 | 53.5M | int n2 = n > s->cur - &(s->stack[0]) ? s->cur - &(s->stack[0]) : n; | 245 | 159M | while(n2--) { | 246 | | /* We only have one dimensional arrays to worry about */ | 247 | 106M | if (pdf_ps_obj_has_type(s->cur, PDF_PS_OBJ_ARRAY)) { | 248 | 1.13M | pdf_ps_free_array_contents(s, s->cur); | 249 | 1.13M | gs_free_object(s->pdfi_ctx->memory, s->cur->val.arr, "pdf_ps_stack_pop(s->cur->val.arr)"); | 250 | 1.13M | } | 251 | 106M | pdf_ps_make_null(s->cur); | 252 | 106M | s->cur--; | 253 | 106M | if (pdf_ps_obj_has_type(s->cur, PDF_PS_OBJ_STACK_TOP)) | 254 | 0 | return_error(gs_error_pdf_stackoverflow); | 255 | 106M | if (pdf_ps_obj_has_type(s->cur, PDF_PS_OBJ_STACK_BOTTOM)) | 256 | 3.28k | return_error(gs_error_stackunderflow); | 257 | 106M | } | 258 | 53.5M | return 0; | 259 | 53.5M | } |
pdf_cmap.c:pdf_ps_stack_pop Line | Count | Source | 243 | 753k | { | 244 | 753k | int n2 = n > s->cur - &(s->stack[0]) ? s->cur - &(s->stack[0]) : n; | 245 | 42.5M | while(n2--) { | 246 | | /* We only have one dimensional arrays to worry about */ | 247 | 41.7M | if (pdf_ps_obj_has_type(s->cur, PDF_PS_OBJ_ARRAY)) { | 248 | 486k | pdf_ps_free_array_contents(s, s->cur); | 249 | 486k | gs_free_object(s->pdfi_ctx->memory, s->cur->val.arr, "pdf_ps_stack_pop(s->cur->val.arr)"); | 250 | 486k | } | 251 | 41.7M | pdf_ps_make_null(s->cur); | 252 | 41.7M | s->cur--; | 253 | 41.7M | if (pdf_ps_obj_has_type(s->cur, PDF_PS_OBJ_STACK_TOP)) | 254 | 0 | return_error(gs_error_pdf_stackoverflow); | 255 | 41.7M | if (pdf_ps_obj_has_type(s->cur, PDF_PS_OBJ_STACK_BOTTOM)) | 256 | 13 | return_error(gs_error_stackunderflow); | 257 | 41.7M | } | 258 | 753k | return 0; | 259 | 753k | } |
|
260 | | |
261 | | static inline int pdf_ps_stack_push_arr_mark(pdf_ps_ctx_t *s) |
262 | 2.16M | { |
263 | 2.16M | int code = pdf_ps_stack_push(s); |
264 | 2.16M | if (code < 0) return code; |
265 | | |
266 | 2.16M | pdf_ps_make_array_mark(s->cur); |
267 | 2.16M | return 0; |
268 | 2.16M | } Unexecuted instantiation: pdf_font1.c:pdf_ps_stack_push_arr_mark Unexecuted instantiation: pdf_font1C.c:pdf_ps_stack_push_arr_mark pdf_fontps.c:pdf_ps_stack_push_arr_mark Line | Count | Source | 262 | 2.16M | { | 263 | 2.16M | int code = pdf_ps_stack_push(s); | 264 | 2.16M | if (code < 0) return code; | 265 | | | 266 | 2.16M | pdf_ps_make_array_mark(s->cur); | 267 | 2.16M | return 0; | 268 | 2.16M | } |
Unexecuted instantiation: pdf_cmap.c:pdf_ps_stack_push_arr_mark |
269 | | |
270 | | static inline int pdf_ps_stack_push_dict_mark(pdf_ps_ctx_t *s) |
271 | 253k | { |
272 | 253k | int code = pdf_ps_stack_push(s); |
273 | 253k | if (code < 0) return code; |
274 | | |
275 | 253k | pdf_ps_make_dict_mark(s->cur); |
276 | 253k | return 0; |
277 | 253k | } Unexecuted instantiation: pdf_font1.c:pdf_ps_stack_push_dict_mark Unexecuted instantiation: pdf_font1C.c:pdf_ps_stack_push_dict_mark pdf_fontps.c:pdf_ps_stack_push_dict_mark Line | Count | Source | 271 | 253k | { | 272 | 253k | int code = pdf_ps_stack_push(s); | 273 | 253k | if (code < 0) return code; | 274 | | | 275 | 253k | pdf_ps_make_dict_mark(s->cur); | 276 | 253k | return 0; | 277 | 253k | } |
Unexecuted instantiation: pdf_cmap.c:pdf_ps_stack_push_dict_mark |
278 | | |
279 | | static inline int pdf_ps_stack_push_mark(pdf_ps_ctx_t *s) |
280 | 277k | { |
281 | 277k | int code = pdf_ps_stack_push(s); |
282 | 277k | if (code < 0) return code; |
283 | | |
284 | 277k | pdf_ps_make_mark(s->cur); |
285 | 277k | return 0; |
286 | 277k | } Unexecuted instantiation: pdf_font1.c:pdf_ps_stack_push_mark Unexecuted instantiation: pdf_font1C.c:pdf_ps_stack_push_mark pdf_fontps.c:pdf_ps_stack_push_mark Line | Count | Source | 280 | 277k | { | 281 | 277k | int code = pdf_ps_stack_push(s); | 282 | 277k | if (code < 0) return code; | 283 | | | 284 | 277k | pdf_ps_make_mark(s->cur); | 285 | 277k | return 0; | 286 | 277k | } |
Unexecuted instantiation: pdf_cmap.c:pdf_ps_stack_push_mark |
287 | | |
288 | | static inline int pdf_ps_stack_push_int(pdf_ps_ctx_t *s, int i) |
289 | 67.0M | { |
290 | 67.0M | int code = pdf_ps_stack_push(s); |
291 | 67.0M | if (code < 0) return code; |
292 | | |
293 | 67.0M | pdf_ps_make_int(s->cur, i); |
294 | 67.0M | return 0; |
295 | 67.0M | } Unexecuted instantiation: pdf_font1.c:pdf_ps_stack_push_int Unexecuted instantiation: pdf_font1C.c:pdf_ps_stack_push_int pdf_fontps.c:pdf_ps_stack_push_int Line | Count | Source | 289 | 67.0M | { | 290 | 67.0M | int code = pdf_ps_stack_push(s); | 291 | 67.0M | if (code < 0) return code; | 292 | | | 293 | 67.0M | pdf_ps_make_int(s->cur, i); | 294 | 67.0M | return 0; | 295 | 67.0M | } |
Unexecuted instantiation: pdf_cmap.c:pdf_ps_stack_push_int |
296 | | |
297 | | static inline int pdf_ps_stack_push_float(pdf_ps_ctx_t *s, float f) |
298 | 532k | { |
299 | 532k | int code = pdf_ps_stack_push(s); |
300 | 532k | if (code < 0) return code; |
301 | | |
302 | 532k | pdf_ps_make_float(s->cur, f); |
303 | 532k | return 0; |
304 | 532k | } Unexecuted instantiation: pdf_font1.c:pdf_ps_stack_push_float Unexecuted instantiation: pdf_font1C.c:pdf_ps_stack_push_float pdf_fontps.c:pdf_ps_stack_push_float Line | Count | Source | 298 | 532k | { | 299 | 532k | int code = pdf_ps_stack_push(s); | 300 | 532k | if (code < 0) return code; | 301 | | | 302 | 532k | pdf_ps_make_float(s->cur, f); | 303 | 532k | return 0; | 304 | 532k | } |
Unexecuted instantiation: pdf_cmap.c:pdf_ps_stack_push_float |
305 | | |
306 | | /* String, name and array have an arbitrary limit of 64k on their size. */ |
307 | | static inline int pdf_ps_stack_push_string(pdf_ps_ctx_t *s, byte *str, uint32_t len) |
308 | 29.5M | { |
309 | 29.5M | int code; |
310 | | |
311 | 29.5M | if (len > 65535) |
312 | 65 | return gs_error_limitcheck; |
313 | | |
314 | 29.5M | code = pdf_ps_stack_push(s); |
315 | 29.5M | if (code < 0) return code; |
316 | | |
317 | 29.5M | pdf_ps_make_string(s->cur, str, len); |
318 | 29.5M | return 0; |
319 | 29.5M | } Unexecuted instantiation: pdf_font1.c:pdf_ps_stack_push_string Unexecuted instantiation: pdf_font1C.c:pdf_ps_stack_push_string pdf_fontps.c:pdf_ps_stack_push_string Line | Count | Source | 308 | 29.5M | { | 309 | 29.5M | int code; | 310 | | | 311 | 29.5M | if (len > 65535) | 312 | 65 | return gs_error_limitcheck; | 313 | | | 314 | 29.5M | code = pdf_ps_stack_push(s); | 315 | 29.5M | if (code < 0) return code; | 316 | | | 317 | 29.5M | pdf_ps_make_string(s->cur, str, len); | 318 | 29.5M | return 0; | 319 | 29.5M | } |
Unexecuted instantiation: pdf_cmap.c:pdf_ps_stack_push_string |
320 | | |
321 | | static inline int pdf_ps_stack_push_name(pdf_ps_ctx_t *s, byte *nm, uint32_t len) |
322 | 45.7M | { |
323 | 45.7M | int code; |
324 | | |
325 | 45.7M | if (len > 65535) |
326 | 0 | return gs_error_limitcheck; |
327 | | |
328 | 45.7M | code = pdf_ps_stack_push(s); |
329 | 45.7M | if (code < 0) return code; |
330 | | |
331 | 45.7M | pdf_ps_make_name(s->cur, nm, len); |
332 | 45.7M | return 0; |
333 | 45.7M | } Unexecuted instantiation: pdf_font1.c:pdf_ps_stack_push_name Unexecuted instantiation: pdf_font1C.c:pdf_ps_stack_push_name pdf_fontps.c:pdf_ps_stack_push_name Line | Count | Source | 322 | 45.7M | { | 323 | 45.7M | int code; | 324 | | | 325 | 45.7M | if (len > 65535) | 326 | 0 | return gs_error_limitcheck; | 327 | | | 328 | 45.7M | code = pdf_ps_stack_push(s); | 329 | 45.7M | if (code < 0) return code; | 330 | | | 331 | 45.7M | pdf_ps_make_name(s->cur, nm, len); | 332 | 45.7M | return 0; | 333 | 45.7M | } |
Unexecuted instantiation: pdf_cmap.c:pdf_ps_stack_push_name |
334 | | |
335 | | static inline int pdf_ps_stack_push_array(pdf_ps_ctx_t *s, pdf_ps_stack_object_t *a, uint32_t len) |
336 | 2.17M | { |
337 | 2.17M | int code; |
338 | | |
339 | 2.17M | if (len > 65535) |
340 | 0 | return gs_error_limitcheck; |
341 | | |
342 | 2.17M | code = pdf_ps_stack_push(s); |
343 | 2.17M | if (code < 0) return code; |
344 | | |
345 | 2.17M | pdf_ps_make_array(s->cur, a, len); |
346 | 2.17M | return 0; |
347 | 2.17M | } Unexecuted instantiation: pdf_font1.c:pdf_ps_stack_push_array Unexecuted instantiation: pdf_font1C.c:pdf_ps_stack_push_array pdf_fontps.c:pdf_ps_stack_push_array Line | Count | Source | 336 | 2.17M | { | 337 | 2.17M | int code; | 338 | | | 339 | 2.17M | if (len > 65535) | 340 | 0 | return gs_error_limitcheck; | 341 | | | 342 | 2.17M | code = pdf_ps_stack_push(s); | 343 | 2.17M | if (code < 0) return code; | 344 | | | 345 | 2.17M | pdf_ps_make_array(s->cur, a, len); | 346 | 2.17M | return 0; | 347 | 2.17M | } |
Unexecuted instantiation: pdf_cmap.c:pdf_ps_stack_push_array |
348 | | |
349 | | static inline int pdf_ps_stack_push_boolean(pdf_ps_ctx_t *s, bool b) |
350 | 127k | { |
351 | 127k | int code = pdf_ps_stack_push(s); |
352 | 127k | if (code < 0) return code; |
353 | | |
354 | 127k | pdf_ps_make_boolean(s->cur, b); |
355 | 127k | return 0; |
356 | 127k | } Unexecuted instantiation: pdf_font1.c:pdf_ps_stack_push_boolean Unexecuted instantiation: pdf_font1C.c:pdf_ps_stack_push_boolean pdf_fontps.c:pdf_ps_stack_push_boolean Line | Count | Source | 350 | 127k | { | 351 | 127k | int code = pdf_ps_stack_push(s); | 352 | 127k | if (code < 0) return code; | 353 | | | 354 | 127k | pdf_ps_make_boolean(s->cur, b); | 355 | 127k | return 0; | 356 | 127k | } |
Unexecuted instantiation: pdf_cmap.c:pdf_ps_stack_push_boolean |
357 | | |
358 | | static inline pdf_ps_obj_type pdf_ps_stack_obj_type(pdf_ps_ctx_t *s) |
359 | 0 | { |
360 | 0 | return s->cur->type; |
361 | 0 | } Unexecuted instantiation: pdf_font1.c:pdf_ps_stack_obj_type Unexecuted instantiation: pdf_font1C.c:pdf_ps_stack_obj_type Unexecuted instantiation: pdf_fontps.c:pdf_ps_stack_obj_type Unexecuted instantiation: pdf_cmap.c:pdf_ps_stack_obj_type |
362 | | |
363 | | static inline int pdf_ps_stack_count_to_mark(pdf_ps_ctx_t *s, pdf_ps_obj_type mtype) |
364 | 2.71M | { |
365 | 2.71M | int i = gs_error_stackunderflow, depth = s->cur - &(s->stack[0]) + 1; |
366 | 53.3M | for (i = 0; i < depth; i++) { |
367 | 53.3M | if (s->cur[-i].type == PDF_PS_OBJ_STACK_BOTTOM) { |
368 | 85.0k | i = gs_note_error(gs_error_unmatchedmark); |
369 | 85.0k | break; |
370 | 85.0k | } |
371 | 53.2M | if (s->cur[-i].type == mtype) |
372 | 2.63M | break; |
373 | 53.2M | } |
374 | 2.71M | return i; |
375 | 2.71M | } Unexecuted instantiation: pdf_font1.c:pdf_ps_stack_count_to_mark Unexecuted instantiation: pdf_font1C.c:pdf_ps_stack_count_to_mark pdf_fontps.c:pdf_ps_stack_count_to_mark Line | Count | Source | 364 | 2.40M | { | 365 | 2.40M | int i = gs_error_stackunderflow, depth = s->cur - &(s->stack[0]) + 1; | 366 | 8.57M | for (i = 0; i < depth; i++) { | 367 | 8.57M | if (s->cur[-i].type == PDF_PS_OBJ_STACK_BOTTOM) { | 368 | 84.4k | i = gs_note_error(gs_error_unmatchedmark); | 369 | 84.4k | break; | 370 | 84.4k | } | 371 | 8.49M | if (s->cur[-i].type == mtype) | 372 | 2.31M | break; | 373 | 8.49M | } | 374 | 2.40M | return i; | 375 | 2.40M | } |
pdf_cmap.c:pdf_ps_stack_count_to_mark Line | Count | Source | 364 | 313k | { | 365 | 313k | int i = gs_error_stackunderflow, depth = s->cur - &(s->stack[0]) + 1; | 366 | 44.7M | for (i = 0; i < depth; i++) { | 367 | 44.7M | if (s->cur[-i].type == PDF_PS_OBJ_STACK_BOTTOM) { | 368 | 608 | i = gs_note_error(gs_error_unmatchedmark); | 369 | 608 | break; | 370 | 608 | } | 371 | 44.7M | if (s->cur[-i].type == mtype) | 372 | 312k | break; | 373 | 44.7M | } | 374 | 313k | return i; | 375 | 313k | } |
|
376 | | |
377 | | static inline int pdf_ps_stack_count(pdf_ps_ctx_t *s) |
378 | 45.9M | { |
379 | 45.9M | return s->cur - &(s->stack[1]); |
380 | 45.9M | } Unexecuted instantiation: pdf_font1.c:pdf_ps_stack_count Unexecuted instantiation: pdf_font1C.c:pdf_ps_stack_count pdf_fontps.c:pdf_ps_stack_count Line | Count | Source | 378 | 45.4M | { | 379 | 45.4M | return s->cur - &(s->stack[1]); | 380 | 45.4M | } |
pdf_cmap.c:pdf_ps_stack_count Line | Count | Source | 378 | 479k | { | 379 | 479k | return s->cur - &(s->stack[1]); | 380 | 479k | } |
|
381 | | |
382 | | #endif |