/src/ghostpdl/psi/zmisc1.c
Line | Count | Source (jump to first uncovered line) |
1 | | /* Copyright (C) 2001-2025 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 | | |
17 | | /* Miscellaneous Type 1 font operators */ |
18 | | #include "memory_.h" |
19 | | #include "ghost.h" |
20 | | #include "oper.h" |
21 | | #include "gscrypt1.h" |
22 | | #include "stream.h" /* for getting state of PFBD stream */ |
23 | | #include "strimpl.h" |
24 | | #include "sfilter.h" |
25 | | #include "idict.h" |
26 | | #include "idparam.h" |
27 | | #include "ifilter.h" |
28 | | |
29 | | /* Get the seed parameter for eexecEncode/Decode. */ |
30 | | /* Return npop if OK. */ |
31 | | static int |
32 | | eexec_param(os_ptr op, ushort * pcstate) |
33 | 0 | { |
34 | 0 | int npop = 1; |
35 | |
|
36 | 0 | if (r_has_type(op, t_dictionary)) |
37 | 0 | ++npop, --op; |
38 | 0 | check_type(*op, t_integer); |
39 | 0 | *pcstate = op->value.intval; |
40 | 0 | if (op->value.intval != *pcstate) |
41 | 0 | return_error(gs_error_rangecheck); /* state value was truncated */ |
42 | 0 | return npop; |
43 | 0 | } |
44 | | |
45 | | /* <source> <seed> eexecDecode/filter <file> */ |
46 | | /* <source> <dict> eexecDecode/filter <file> */ |
47 | | static int |
48 | | zexD(i_ctx_t *i_ctx_p) |
49 | 13.4k | { |
50 | 13.4k | os_ptr op = osp; |
51 | 13.4k | stream_exD_state state = {0}; |
52 | 13.4k | int code = 0; |
53 | | |
54 | 13.4k | check_op(2); |
55 | 13.4k | (*s_exD_template.set_defaults)((stream_state *)&state); |
56 | 13.4k | if (r_has_type(op, t_dictionary)) { |
57 | 13.4k | uint cstate = 0; |
58 | 13.4k | bool is_eexec = false; |
59 | | |
60 | 13.4k | check_dict_read(*op); |
61 | 13.4k | if ((code = dict_uint_param(op, "seed", 0, 0xffff, 0x10000, |
62 | 13.4k | &cstate)) < 0 || |
63 | 13.4k | (code = dict_int_param(op, "lenIV", 0, max_int, 4, |
64 | 13.4k | &state.lenIV)) < 0 || |
65 | 13.4k | (code = dict_bool_param(op, "eexec", false, |
66 | 13.4k | &is_eexec)) < 0 || |
67 | 13.4k | (code = dict_bool_param(op, "keep_spaces", false, |
68 | 13.4k | &state.keep_spaces)) < 0 |
69 | 13.4k | ) |
70 | 0 | return code; |
71 | 13.4k | state.cstate = cstate; |
72 | 13.4k | state.binary = (is_eexec ? -1 : 1); |
73 | 13.4k | code = 1; |
74 | 13.4k | } else { |
75 | 0 | state.binary = 1; |
76 | 0 | code = eexec_param(op, &state.cstate); |
77 | 0 | } |
78 | 13.4k | if (code < 0) |
79 | 0 | return code; |
80 | | |
81 | 13.4k | if (gs_is_path_control_active(imemory) != 0 && state.cstate != 55665) { |
82 | 0 | return_error(gs_error_rangecheck); |
83 | 0 | } |
84 | | |
85 | | /* |
86 | | * If we're reading a .PFB file, let the filter know about it, |
87 | | * so it can read recklessly to the end of the binary section. |
88 | | */ |
89 | 13.4k | if (r_has_type(op - 1, t_file)) { |
90 | 13.4k | stream *s = (op - 1)->value.pfile; |
91 | | |
92 | 13.4k | if (s->state != 0 && s->state->templat == &s_PFBD_template) { |
93 | 0 | stream_PFBD_state *pss = (stream_PFBD_state *)s->state; |
94 | |
|
95 | 0 | state.pfb_state = pss; |
96 | | /* |
97 | | * If we're reading the binary section of a PFB stream, |
98 | | * avoid the conversion from binary to hex and back again. |
99 | | */ |
100 | 0 | if (pss->record_type == 2) { |
101 | | /* |
102 | | * The PFB decoder may have converted some data to hex |
103 | | * already. Convert it back if necessary. |
104 | | */ |
105 | 0 | if (pss->binary_to_hex && sbufavailable(s) > 0) { |
106 | 0 | state.binary = 0; /* start as hex */ |
107 | 0 | state.hex_left = sbufavailable(s); |
108 | 0 | } else { |
109 | 0 | state.binary = 1; |
110 | 0 | } |
111 | 0 | pss->binary_to_hex = 0; |
112 | 0 | } |
113 | 0 | } |
114 | 13.4k | } |
115 | 13.4k | return filter_read(i_ctx_p, code, &s_exD_template, (stream_state *)&state, 0); |
116 | 13.4k | } |
117 | | |
118 | | /* ------ Initialization procedure ------ */ |
119 | | |
120 | | const op_def zmisc1_op_defs[] = |
121 | | { |
122 | | op_def_begin_filter(), |
123 | | {"2eexecDecode", zexD}, |
124 | | op_def_end(0) |
125 | | }; |