Coverage Report

Created: 2026-09-13 07:02

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/imagemagick/coders/ghostscript-private.h
Line
Count
Source
1
/*
2
  Copyright @ 1999 ImageMagick Studio LLC, a non-profit organization
3
  dedicated to making software imaging solutions freely available.
4
5
  You may not use this file except in compliance with the License.  You may
6
  obtain a copy of the License at
7
8
    https://imagemagick.org/license/
9
10
  Unless required by applicable law or agreed to in writing, software
11
  distributed under the License is distributed on an "AS IS" BASIS,
12
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
  See the License for the specific language governing permissions and
14
  limitations under the License.
15
*/
16
#ifndef MAGICK_GHOSTSCRIPT_BUFFER_PRIVATE_H
17
#define MAGICK_GHOSTSCRIPT_BUFFER_PRIVATE_H
18
19
#include "MagickCore/delegate.h"
20
#include "MagickCore/delegate-private.h"
21
#include "MagickCore/exception-private.h"
22
#include "MagickCore/profile-private.h"
23
#include "coders/bytebuffer-private.h"
24
25
#if defined(MAGICKCORE_GS_DELEGATE) || defined(MAGICKCORE_WINDOWS_SUPPORT)
26
static int MagickDLLCall GhostscriptDelegateMessage(void *handle,
27
  const char *message,int length)
28
{
29
  char
30
    **messages;
31
32
  ssize_t
33
    offset;
34
35
  offset=0;
36
  messages=(char **) handle;
37
  if (*messages == (char *) NULL)
38
    *messages=(char *) AcquireQuantumMemory((size_t) length+1,sizeof(char *));
39
  else
40
    {
41
      offset=(ssize_t) strlen(*messages);
42
      *messages=(char *) ResizeQuantumMemory(*messages,(size_t) (offset+length+
43
        1),sizeof(char *));
44
    }
45
  if (*messages == (char *) NULL)
46
    return(0);
47
  (void) memcpy(*messages+offset,message,(size_t) length);
48
  (*messages)[length+offset] ='\0';
49
  return(length);
50
}
51
52
static double GhostscriptVersion(const GhostInfo *ghost_info)
53
{
54
  gsapi_revision_t
55
    revision;
56
57
  if ((ghost_info->revision)(&revision,(int) sizeof(revision)) != 0)
58
    return(0.0);
59
  if (revision.revision > 1000)
60
    return((double) revision.revision/1000.0);
61
  return((double) revision.revision/100.0);
62
}
63
#endif
64
65
static inline MagickBooleanType ExecuteGhostscriptCommand(
66
  const MagickBooleanType verbose,const char *command,char *message,
67
  ExceptionInfo *exception)
68
55.7k
{
69
55.7k
  int
70
55.7k
    status;
71
72
55.7k
  status=ExternalDelegateCommand(MagickFalse,verbose,command,message,
73
55.7k
    exception);
74
55.7k
  if (status == 0)
75
0
    return(MagickTrue);
76
55.7k
  if (status < 0)
77
0
    return(MagickFalse);
78
55.7k
  (void) ThrowMagickException(exception,GetMagickModule(),DelegateError,
79
55.7k
    "FailedToExecuteCommand","`%s' (%d)",command,status);
80
55.7k
  return(MagickFalse);
81
55.7k
}
Unexecuted instantiation: annotate.c:ExecuteGhostscriptCommand
pdf.c:ExecuteGhostscriptCommand
Line
Count
Source
68
4.94k
{
69
4.94k
  int
70
4.94k
    status;
71
72
4.94k
  status=ExternalDelegateCommand(MagickFalse,verbose,command,message,
73
4.94k
    exception);
74
4.94k
  if (status == 0)
75
0
    return(MagickTrue);
76
4.94k
  if (status < 0)
77
0
    return(MagickFalse);
78
4.94k
  (void) ThrowMagickException(exception,GetMagickModule(),DelegateError,
79
4.94k
    "FailedToExecuteCommand","`%s' (%d)",command,status);
80
4.94k
  return(MagickFalse);
81
4.94k
}
Unexecuted instantiation: ps2.c:ExecuteGhostscriptCommand
Unexecuted instantiation: ps3.c:ExecuteGhostscriptCommand
ps.c:ExecuteGhostscriptCommand
Line
Count
Source
68
50.7k
{
69
50.7k
  int
70
50.7k
    status;
71
72
50.7k
  status=ExternalDelegateCommand(MagickFalse,verbose,command,message,
73
50.7k
    exception);
74
50.7k
  if (status == 0)
75
0
    return(MagickTrue);
76
50.7k
  if (status < 0)
77
0
    return(MagickFalse);
78
50.7k
  (void) ThrowMagickException(exception,GetMagickModule(),DelegateError,
79
50.7k
    "FailedToExecuteCommand","`%s' (%d)",command,status);
80
50.7k
  return(MagickFalse);
81
50.7k
}
Unexecuted instantiation: xps.c:ExecuteGhostscriptCommand
82
83
static inline MagickBooleanType InvokeGhostscriptDelegate(
84
  const MagickBooleanType verbose,const char *command,char *message,
85
  ExceptionInfo *exception)
86
55.7k
{
87
#if defined(MAGICKCORE_GS_DELEGATE) || defined(MAGICKCORE_WINDOWS_SUPPORT)
88
#define SetArgsStart(command,args_start) \
89
  if (args_start == (const char *) NULL) \
90
    { \
91
      if (*command != '"') \
92
        args_start=strchr(command,' '); \
93
      else \
94
        { \
95
          args_start=strchr(command+1,'"'); \
96
          if (args_start != (const char *) NULL) \
97
            args_start++; \
98
        } \
99
    }
100
101
  char
102
    **argv,
103
    *errors;
104
105
  const char
106
    *args_start = (const char *) NULL;
107
108
  const GhostInfo
109
    *ghost_info;
110
111
  gs_main_instance
112
    *interpreter;
113
114
  int
115
    argc,
116
    code,
117
    status;
118
119
  ssize_t
120
    i;
121
122
#if defined(MAGICKCORE_WINDOWS_SUPPORT)
123
  ghost_info=NTGhostscriptDLLVectors();
124
#else
125
  GhostInfo
126
    ghost_info_struct;
127
128
  ghost_info=(&ghost_info_struct);
129
  (void) memset(&ghost_info_struct,0,sizeof(ghost_info_struct));
130
  ghost_info_struct.delete_instance=(void (*)(gs_main_instance *))
131
    gsapi_delete_instance;
132
  ghost_info_struct.exit=(int (*)(gs_main_instance *)) gsapi_exit;
133
  ghost_info_struct.new_instance=(int (*)(gs_main_instance **,void *))
134
    gsapi_new_instance;
135
  ghost_info_struct.init_with_args=(int (*)(gs_main_instance *,int,char **))
136
    gsapi_init_with_args;
137
  ghost_info_struct.run_string=(int (*)(gs_main_instance *,const char *,int,
138
    int *)) gsapi_run_string;
139
  ghost_info_struct.set_arg_encoding=(int (*)(gs_main_instance*, int))
140
    gsapi_set_arg_encoding;
141
  ghost_info_struct.set_stdio=(int (*)(gs_main_instance *,int (*)(void *,char *,
142
    int),int (*)(void *,const char *,int),int (*)(void *, const char *, int)))
143
    gsapi_set_stdio;
144
  ghost_info_struct.revision=(int (*)(gsapi_revision_t *,int)) gsapi_revision;
145
#endif
146
  if (ghost_info == (GhostInfo *) NULL)
147
    return(ExecuteGhostscriptCommand(verbose,command,message,exception));
148
  if (verbose != MagickFalse)
149
    {
150
      (void) fprintf(stdout,"[ghostscript library %.2f]",
151
        GhostscriptVersion(ghost_info));
152
      SetArgsStart(command,args_start);
153
      (void) fputs(args_start,stdout);
154
    }
155
  interpreter=(gs_main_instance *) NULL;
156
  errors=(char *) NULL;
157
  status=(ghost_info->new_instance)(&interpreter,(void *) &errors);
158
  if (status < 0)
159
    return(ExecuteGhostscriptCommand(verbose,command,message,exception));
160
  code=0;
161
  argv=StringToArgv(command,&argc);
162
  if (argv == (char **) NULL)
163
    {
164
      (ghost_info->delete_instance)(interpreter);
165
      return(MagickFalse);
166
    }
167
  (void) (ghost_info->set_stdio)(interpreter,(int (MagickDLLCall *)(void *,
168
    char *,int)) NULL,GhostscriptDelegateMessage,GhostscriptDelegateMessage);
169
  (void) ghost_info->set_arg_encoding(interpreter,1);
170
  status=(ghost_info->init_with_args)(interpreter,argc-1,argv+1);
171
  if (status == 0)
172
    status=(ghost_info->run_string)(interpreter,"systemdict /start get exec\n",
173
      0,&code);
174
  (ghost_info->exit)(interpreter);
175
  (ghost_info->delete_instance)(interpreter);
176
  for (i=0; i < (ssize_t) argc; i++)
177
    argv[i]=DestroyString(argv[i]);
178
  argv=(char **) RelinquishMagickMemory(argv);
179
  if (status != 0)
180
    {
181
      SetArgsStart(command,args_start);
182
      if (status == -101) /* quit */
183
        (void) FormatLocaleString(message,MaxTextExtent,
184
          "[ghostscript library %.2f]%s: %s",GhostscriptVersion(ghost_info),
185
          args_start,errors);
186
      else
187
        {
188
          (void) ThrowMagickException(exception,GetMagickModule(),
189
            DelegateError,"PostscriptDelegateFailed",
190
            "`[ghostscript library %.2f]%s': %s",GhostscriptVersion(ghost_info),
191
            args_start,errors);
192
          if (errors != (char *) NULL)
193
            errors=DestroyString(errors);
194
          (void) LogMagickEvent(CoderEvent,GetMagickModule(),
195
            "Ghostscript returns status %d, exit code %d",status,code);
196
          return(MagickFalse);
197
        }
198
    }
199
  if (errors != (char *) NULL)
200
    errors=DestroyString(errors);
201
  return(MagickTrue);
202
#else
203
55.7k
  return(ExecuteGhostscriptCommand(verbose,command,message,exception));
204
55.7k
#endif
205
55.7k
}
Unexecuted instantiation: annotate.c:InvokeGhostscriptDelegate
pdf.c:InvokeGhostscriptDelegate
Line
Count
Source
86
4.94k
{
87
#if defined(MAGICKCORE_GS_DELEGATE) || defined(MAGICKCORE_WINDOWS_SUPPORT)
88
#define SetArgsStart(command,args_start) \
89
  if (args_start == (const char *) NULL) \
90
    { \
91
      if (*command != '"') \
92
        args_start=strchr(command,' '); \
93
      else \
94
        { \
95
          args_start=strchr(command+1,'"'); \
96
          if (args_start != (const char *) NULL) \
97
            args_start++; \
98
        } \
99
    }
100
101
  char
102
    **argv,
103
    *errors;
104
105
  const char
106
    *args_start = (const char *) NULL;
107
108
  const GhostInfo
109
    *ghost_info;
110
111
  gs_main_instance
112
    *interpreter;
113
114
  int
115
    argc,
116
    code,
117
    status;
118
119
  ssize_t
120
    i;
121
122
#if defined(MAGICKCORE_WINDOWS_SUPPORT)
123
  ghost_info=NTGhostscriptDLLVectors();
124
#else
125
  GhostInfo
126
    ghost_info_struct;
127
128
  ghost_info=(&ghost_info_struct);
129
  (void) memset(&ghost_info_struct,0,sizeof(ghost_info_struct));
130
  ghost_info_struct.delete_instance=(void (*)(gs_main_instance *))
131
    gsapi_delete_instance;
132
  ghost_info_struct.exit=(int (*)(gs_main_instance *)) gsapi_exit;
133
  ghost_info_struct.new_instance=(int (*)(gs_main_instance **,void *))
134
    gsapi_new_instance;
135
  ghost_info_struct.init_with_args=(int (*)(gs_main_instance *,int,char **))
136
    gsapi_init_with_args;
137
  ghost_info_struct.run_string=(int (*)(gs_main_instance *,const char *,int,
138
    int *)) gsapi_run_string;
139
  ghost_info_struct.set_arg_encoding=(int (*)(gs_main_instance*, int))
140
    gsapi_set_arg_encoding;
141
  ghost_info_struct.set_stdio=(int (*)(gs_main_instance *,int (*)(void *,char *,
142
    int),int (*)(void *,const char *,int),int (*)(void *, const char *, int)))
143
    gsapi_set_stdio;
144
  ghost_info_struct.revision=(int (*)(gsapi_revision_t *,int)) gsapi_revision;
145
#endif
146
  if (ghost_info == (GhostInfo *) NULL)
147
    return(ExecuteGhostscriptCommand(verbose,command,message,exception));
148
  if (verbose != MagickFalse)
149
    {
150
      (void) fprintf(stdout,"[ghostscript library %.2f]",
151
        GhostscriptVersion(ghost_info));
152
      SetArgsStart(command,args_start);
153
      (void) fputs(args_start,stdout);
154
    }
155
  interpreter=(gs_main_instance *) NULL;
156
  errors=(char *) NULL;
157
  status=(ghost_info->new_instance)(&interpreter,(void *) &errors);
158
  if (status < 0)
159
    return(ExecuteGhostscriptCommand(verbose,command,message,exception));
160
  code=0;
161
  argv=StringToArgv(command,&argc);
162
  if (argv == (char **) NULL)
163
    {
164
      (ghost_info->delete_instance)(interpreter);
165
      return(MagickFalse);
166
    }
167
  (void) (ghost_info->set_stdio)(interpreter,(int (MagickDLLCall *)(void *,
168
    char *,int)) NULL,GhostscriptDelegateMessage,GhostscriptDelegateMessage);
169
  (void) ghost_info->set_arg_encoding(interpreter,1);
170
  status=(ghost_info->init_with_args)(interpreter,argc-1,argv+1);
171
  if (status == 0)
172
    status=(ghost_info->run_string)(interpreter,"systemdict /start get exec\n",
173
      0,&code);
174
  (ghost_info->exit)(interpreter);
175
  (ghost_info->delete_instance)(interpreter);
176
  for (i=0; i < (ssize_t) argc; i++)
177
    argv[i]=DestroyString(argv[i]);
178
  argv=(char **) RelinquishMagickMemory(argv);
179
  if (status != 0)
180
    {
181
      SetArgsStart(command,args_start);
182
      if (status == -101) /* quit */
183
        (void) FormatLocaleString(message,MaxTextExtent,
184
          "[ghostscript library %.2f]%s: %s",GhostscriptVersion(ghost_info),
185
          args_start,errors);
186
      else
187
        {
188
          (void) ThrowMagickException(exception,GetMagickModule(),
189
            DelegateError,"PostscriptDelegateFailed",
190
            "`[ghostscript library %.2f]%s': %s",GhostscriptVersion(ghost_info),
191
            args_start,errors);
192
          if (errors != (char *) NULL)
193
            errors=DestroyString(errors);
194
          (void) LogMagickEvent(CoderEvent,GetMagickModule(),
195
            "Ghostscript returns status %d, exit code %d",status,code);
196
          return(MagickFalse);
197
        }
198
    }
199
  if (errors != (char *) NULL)
200
    errors=DestroyString(errors);
201
  return(MagickTrue);
202
#else
203
4.94k
  return(ExecuteGhostscriptCommand(verbose,command,message,exception));
204
4.94k
#endif
205
4.94k
}
Unexecuted instantiation: ps2.c:InvokeGhostscriptDelegate
Unexecuted instantiation: ps3.c:InvokeGhostscriptDelegate
ps.c:InvokeGhostscriptDelegate
Line
Count
Source
86
50.7k
{
87
#if defined(MAGICKCORE_GS_DELEGATE) || defined(MAGICKCORE_WINDOWS_SUPPORT)
88
#define SetArgsStart(command,args_start) \
89
  if (args_start == (const char *) NULL) \
90
    { \
91
      if (*command != '"') \
92
        args_start=strchr(command,' '); \
93
      else \
94
        { \
95
          args_start=strchr(command+1,'"'); \
96
          if (args_start != (const char *) NULL) \
97
            args_start++; \
98
        } \
99
    }
100
101
  char
102
    **argv,
103
    *errors;
104
105
  const char
106
    *args_start = (const char *) NULL;
107
108
  const GhostInfo
109
    *ghost_info;
110
111
  gs_main_instance
112
    *interpreter;
113
114
  int
115
    argc,
116
    code,
117
    status;
118
119
  ssize_t
120
    i;
121
122
#if defined(MAGICKCORE_WINDOWS_SUPPORT)
123
  ghost_info=NTGhostscriptDLLVectors();
124
#else
125
  GhostInfo
126
    ghost_info_struct;
127
128
  ghost_info=(&ghost_info_struct);
129
  (void) memset(&ghost_info_struct,0,sizeof(ghost_info_struct));
130
  ghost_info_struct.delete_instance=(void (*)(gs_main_instance *))
131
    gsapi_delete_instance;
132
  ghost_info_struct.exit=(int (*)(gs_main_instance *)) gsapi_exit;
133
  ghost_info_struct.new_instance=(int (*)(gs_main_instance **,void *))
134
    gsapi_new_instance;
135
  ghost_info_struct.init_with_args=(int (*)(gs_main_instance *,int,char **))
136
    gsapi_init_with_args;
137
  ghost_info_struct.run_string=(int (*)(gs_main_instance *,const char *,int,
138
    int *)) gsapi_run_string;
139
  ghost_info_struct.set_arg_encoding=(int (*)(gs_main_instance*, int))
140
    gsapi_set_arg_encoding;
141
  ghost_info_struct.set_stdio=(int (*)(gs_main_instance *,int (*)(void *,char *,
142
    int),int (*)(void *,const char *,int),int (*)(void *, const char *, int)))
143
    gsapi_set_stdio;
144
  ghost_info_struct.revision=(int (*)(gsapi_revision_t *,int)) gsapi_revision;
145
#endif
146
  if (ghost_info == (GhostInfo *) NULL)
147
    return(ExecuteGhostscriptCommand(verbose,command,message,exception));
148
  if (verbose != MagickFalse)
149
    {
150
      (void) fprintf(stdout,"[ghostscript library %.2f]",
151
        GhostscriptVersion(ghost_info));
152
      SetArgsStart(command,args_start);
153
      (void) fputs(args_start,stdout);
154
    }
155
  interpreter=(gs_main_instance *) NULL;
156
  errors=(char *) NULL;
157
  status=(ghost_info->new_instance)(&interpreter,(void *) &errors);
158
  if (status < 0)
159
    return(ExecuteGhostscriptCommand(verbose,command,message,exception));
160
  code=0;
161
  argv=StringToArgv(command,&argc);
162
  if (argv == (char **) NULL)
163
    {
164
      (ghost_info->delete_instance)(interpreter);
165
      return(MagickFalse);
166
    }
167
  (void) (ghost_info->set_stdio)(interpreter,(int (MagickDLLCall *)(void *,
168
    char *,int)) NULL,GhostscriptDelegateMessage,GhostscriptDelegateMessage);
169
  (void) ghost_info->set_arg_encoding(interpreter,1);
170
  status=(ghost_info->init_with_args)(interpreter,argc-1,argv+1);
171
  if (status == 0)
172
    status=(ghost_info->run_string)(interpreter,"systemdict /start get exec\n",
173
      0,&code);
174
  (ghost_info->exit)(interpreter);
175
  (ghost_info->delete_instance)(interpreter);
176
  for (i=0; i < (ssize_t) argc; i++)
177
    argv[i]=DestroyString(argv[i]);
178
  argv=(char **) RelinquishMagickMemory(argv);
179
  if (status != 0)
180
    {
181
      SetArgsStart(command,args_start);
182
      if (status == -101) /* quit */
183
        (void) FormatLocaleString(message,MaxTextExtent,
184
          "[ghostscript library %.2f]%s: %s",GhostscriptVersion(ghost_info),
185
          args_start,errors);
186
      else
187
        {
188
          (void) ThrowMagickException(exception,GetMagickModule(),
189
            DelegateError,"PostscriptDelegateFailed",
190
            "`[ghostscript library %.2f]%s': %s",GhostscriptVersion(ghost_info),
191
            args_start,errors);
192
          if (errors != (char *) NULL)
193
            errors=DestroyString(errors);
194
          (void) LogMagickEvent(CoderEvent,GetMagickModule(),
195
            "Ghostscript returns status %d, exit code %d",status,code);
196
          return(MagickFalse);
197
        }
198
    }
199
  if (errors != (char *) NULL)
200
    errors=DestroyString(errors);
201
  return(MagickTrue);
202
#else
203
50.7k
  return(ExecuteGhostscriptCommand(verbose,command,message,exception));
204
50.7k
#endif
205
50.7k
}
Unexecuted instantiation: xps.c:InvokeGhostscriptDelegate
206
207
static inline MagickBooleanType IsGhostscriptRendered(const char *path)
208
30.3k
{
209
30.3k
  MagickBooleanType
210
30.3k
    status;
211
212
30.3k
  struct stat
213
30.3k
    attributes;
214
215
30.3k
  if ((path == (const char *) NULL) || (*path == '\0'))
216
0
    return(MagickFalse);
217
30.3k
  status=GetPathAttributes(path,&attributes);
218
30.3k
  if ((status != MagickFalse) && S_ISREG(attributes.st_mode) &&
219
0
      (attributes.st_size > 0))
220
0
    return(MagickTrue);
221
30.3k
  return(MagickFalse);
222
30.3k
}
Unexecuted instantiation: annotate.c:IsGhostscriptRendered
pdf.c:IsGhostscriptRendered
Line
Count
Source
208
4.94k
{
209
4.94k
  MagickBooleanType
210
4.94k
    status;
211
212
4.94k
  struct stat
213
4.94k
    attributes;
214
215
4.94k
  if ((path == (const char *) NULL) || (*path == '\0'))
216
0
    return(MagickFalse);
217
4.94k
  status=GetPathAttributes(path,&attributes);
218
4.94k
  if ((status != MagickFalse) && S_ISREG(attributes.st_mode) &&
219
0
      (attributes.st_size > 0))
220
0
    return(MagickTrue);
221
4.94k
  return(MagickFalse);
222
4.94k
}
Unexecuted instantiation: ps2.c:IsGhostscriptRendered
Unexecuted instantiation: ps3.c:IsGhostscriptRendered
ps.c:IsGhostscriptRendered
Line
Count
Source
208
25.3k
{
209
25.3k
  MagickBooleanType
210
25.3k
    status;
211
212
25.3k
  struct stat
213
25.3k
    attributes;
214
215
25.3k
  if ((path == (const char *) NULL) || (*path == '\0'))
216
0
    return(MagickFalse);
217
25.3k
  status=GetPathAttributes(path,&attributes);
218
25.3k
  if ((status != MagickFalse) && S_ISREG(attributes.st_mode) &&
219
0
      (attributes.st_size > 0))
220
0
    return(MagickTrue);
221
25.3k
  return(MagickFalse);
222
25.3k
}
Unexecuted instantiation: xps.c:IsGhostscriptRendered
223
224
static inline void ReadGhostScriptXMPProfile(MagickByteBuffer *buffer,
225
  StringInfo **profile,ExceptionInfo *exception)
226
98.2k
{
227
196k
#define BeginXMPPacket  "?xpacket begin="
228
13.9M
#define EndXMPPacket  "<?xpacket end="
229
230
98.2k
  int
231
98.2k
    c;
232
233
98.2k
  MagickBooleanType
234
98.2k
    found_end,
235
98.2k
    status;
236
237
98.2k
  char
238
98.2k
    *p;
239
240
98.2k
  size_t
241
98.2k
    length;
242
243
98.2k
  ssize_t
244
98.2k
    count;
245
246
98.2k
  status=CompareMagickByteBuffer(buffer,BeginXMPPacket,strlen(BeginXMPPacket));
247
98.2k
  if (status == MagickFalse)
248
58.2k
    return;
249
39.9k
  if (*profile != (StringInfo *) NULL)
250
37.1k
    *profile=DestroyStringInfo(*profile);
251
39.9k
  length=8192;
252
39.9k
  *profile=AcquireProfileStringInfo("xmp",length,exception);
253
39.9k
  if (*profile == (StringInfo *) NULL)
254
0
    return;
255
39.9k
  found_end=MagickFalse;
256
39.9k
  p=(char *) GetStringInfoDatum(*profile);
257
39.9k
  *p++='<';
258
39.9k
  count=1;
259
8.66M
  for (c=ReadMagickByteBuffer(buffer); c != EOF; c=ReadMagickByteBuffer(buffer))
260
8.66M
  {
261
8.66M
    if (count == (ssize_t) length)
262
223
      {
263
223
        length<<=1;
264
223
        SetStringInfoLength(*profile,length);
265
223
        p=(char *) GetStringInfoDatum(*profile)+count;
266
223
      }
267
8.66M
    count++;
268
8.66M
    *p++=(char) c;
269
8.66M
    if (found_end == MagickFalse)
270
6.96M
      found_end=CompareMagickByteBuffer(buffer,EndXMPPacket,
271
6.96M
        strlen(EndXMPPacket));
272
1.70M
    else
273
1.70M
      {
274
1.70M
        if (c == (int) '>')
275
37.8k
          break;
276
1.70M
      }
277
8.66M
  }
278
39.9k
  SetStringInfoLength(*profile,(size_t) count);
279
39.9k
}
Unexecuted instantiation: annotate.c:ReadGhostScriptXMPProfile
pdf.c:ReadGhostScriptXMPProfile
Line
Count
Source
226
51.3k
{
227
51.3k
#define BeginXMPPacket  "?xpacket begin="
228
51.3k
#define EndXMPPacket  "<?xpacket end="
229
230
51.3k
  int
231
51.3k
    c;
232
233
51.3k
  MagickBooleanType
234
51.3k
    found_end,
235
51.3k
    status;
236
237
51.3k
  char
238
51.3k
    *p;
239
240
51.3k
  size_t
241
51.3k
    length;
242
243
51.3k
  ssize_t
244
51.3k
    count;
245
246
51.3k
  status=CompareMagickByteBuffer(buffer,BeginXMPPacket,strlen(BeginXMPPacket));
247
51.3k
  if (status == MagickFalse)
248
31.6k
    return;
249
19.6k
  if (*profile != (StringInfo *) NULL)
250
18.8k
    *profile=DestroyStringInfo(*profile);
251
19.6k
  length=8192;
252
19.6k
  *profile=AcquireProfileStringInfo("xmp",length,exception);
253
19.6k
  if (*profile == (StringInfo *) NULL)
254
0
    return;
255
19.6k
  found_end=MagickFalse;
256
19.6k
  p=(char *) GetStringInfoDatum(*profile);
257
19.6k
  *p++='<';
258
19.6k
  count=1;
259
3.51M
  for (c=ReadMagickByteBuffer(buffer); c != EOF; c=ReadMagickByteBuffer(buffer))
260
3.51M
  {
261
3.51M
    if (count == (ssize_t) length)
262
9
      {
263
9
        length<<=1;
264
9
        SetStringInfoLength(*profile,length);
265
9
        p=(char *) GetStringInfoDatum(*profile)+count;
266
9
      }
267
3.51M
    count++;
268
3.51M
    *p++=(char) c;
269
3.51M
    if (found_end == MagickFalse)
270
3.17M
      found_end=CompareMagickByteBuffer(buffer,EndXMPPacket,
271
3.17M
        strlen(EndXMPPacket));
272
335k
    else
273
335k
      {
274
335k
        if (c == (int) '>')
275
18.9k
          break;
276
335k
      }
277
3.51M
  }
278
19.6k
  SetStringInfoLength(*profile,(size_t) count);
279
19.6k
}
Unexecuted instantiation: ps2.c:ReadGhostScriptXMPProfile
Unexecuted instantiation: ps3.c:ReadGhostScriptXMPProfile
ps.c:ReadGhostScriptXMPProfile
Line
Count
Source
226
46.8k
{
227
46.8k
#define BeginXMPPacket  "?xpacket begin="
228
46.8k
#define EndXMPPacket  "<?xpacket end="
229
230
46.8k
  int
231
46.8k
    c;
232
233
46.8k
  MagickBooleanType
234
46.8k
    found_end,
235
46.8k
    status;
236
237
46.8k
  char
238
46.8k
    *p;
239
240
46.8k
  size_t
241
46.8k
    length;
242
243
46.8k
  ssize_t
244
46.8k
    count;
245
246
46.8k
  status=CompareMagickByteBuffer(buffer,BeginXMPPacket,strlen(BeginXMPPacket));
247
46.8k
  if (status == MagickFalse)
248
26.5k
    return;
249
20.3k
  if (*profile != (StringInfo *) NULL)
250
18.2k
    *profile=DestroyStringInfo(*profile);
251
20.3k
  length=8192;
252
20.3k
  *profile=AcquireProfileStringInfo("xmp",length,exception);
253
20.3k
  if (*profile == (StringInfo *) NULL)
254
0
    return;
255
20.3k
  found_end=MagickFalse;
256
20.3k
  p=(char *) GetStringInfoDatum(*profile);
257
20.3k
  *p++='<';
258
20.3k
  count=1;
259
5.15M
  for (c=ReadMagickByteBuffer(buffer); c != EOF; c=ReadMagickByteBuffer(buffer))
260
5.15M
  {
261
5.15M
    if (count == (ssize_t) length)
262
214
      {
263
214
        length<<=1;
264
214
        SetStringInfoLength(*profile,length);
265
214
        p=(char *) GetStringInfoDatum(*profile)+count;
266
214
      }
267
5.15M
    count++;
268
5.15M
    *p++=(char) c;
269
5.15M
    if (found_end == MagickFalse)
270
3.78M
      found_end=CompareMagickByteBuffer(buffer,EndXMPPacket,
271
3.78M
        strlen(EndXMPPacket));
272
1.36M
    else
273
1.36M
      {
274
1.36M
        if (c == (int) '>')
275
18.8k
          break;
276
1.36M
      }
277
5.15M
  }
278
20.3k
  SetStringInfoLength(*profile,(size_t) count);
279
20.3k
}
Unexecuted instantiation: xps.c:ReadGhostScriptXMPProfile
280
281
static inline char *EscapeParenthesis(const char *source,
282
  const size_t max_length,ExceptionInfo *exception)
283
13.3k
{
284
13.3k
  char
285
13.3k
    *destination;
286
287
13.3k
  char
288
13.3k
    *q;
289
290
13.3k
  const char
291
13.3k
    *end,
292
13.3k
    *p;
293
294
13.3k
  size_t
295
13.3k
    length;
296
297
13.3k
  assert(source != (const char *) NULL);
298
13.3k
  length=0;
299
13.3k
  end=source;
300
19.7M
  for (p=source; *p != '\0'; p++)
301
19.7M
  {
302
19.7M
    size_t
303
19.7M
      count;
304
305
19.7M
    count=((*p == '\\') || (*p == '(') || (*p == ')')) ? 2 : 1;
306
19.7M
    if ((~length < count) || ((length+count) > max_length))
307
0
      break;
308
19.7M
    length+=count;
309
19.7M
    end=p+1;
310
19.7M
  }
311
13.3k
  if (*end != '\0')
312
0
    (void) ThrowMagickException(exception,GetMagickModule(),CoderWarning,
313
0
      "LabelTruncated","`%g'",(double) max_length);
314
13.3k
  destination=(char *) NULL;
315
13.3k
  if (~length >= (MagickPathExtent-1))
316
13.3k
    destination=(char *) AcquireQuantumMemory(length+MagickPathExtent,
317
13.3k
      sizeof(*destination));
318
13.3k
  if (destination == (char *) NULL)
319
13.3k
    ThrowFatalException(ResourceLimitFatalError,"UnableToEscapeString");
320
13.3k
  *destination='\0';
321
13.3k
  q=destination;
322
19.7M
  for (p=source; p < end; p++)
323
19.7M
  {
324
19.7M
    if ((*p == '\\') || (*p == '(') || (*p == ')'))
325
7.86M
      *q++='\\';
326
19.7M
    *q++=(*p);
327
19.7M
  }
328
13.3k
  *q='\0';
329
13.3k
  return(destination);
330
13.3k
}
annotate.c:EscapeParenthesis
Line
Count
Source
283
13.3k
{
284
13.3k
  char
285
13.3k
    *destination;
286
287
13.3k
  char
288
13.3k
    *q;
289
290
13.3k
  const char
291
13.3k
    *end,
292
13.3k
    *p;
293
294
13.3k
  size_t
295
13.3k
    length;
296
297
13.3k
  assert(source != (const char *) NULL);
298
13.3k
  length=0;
299
13.3k
  end=source;
300
19.7M
  for (p=source; *p != '\0'; p++)
301
19.7M
  {
302
19.7M
    size_t
303
19.7M
      count;
304
305
19.7M
    count=((*p == '\\') || (*p == '(') || (*p == ')')) ? 2 : 1;
306
19.7M
    if ((~length < count) || ((length+count) > max_length))
307
0
      break;
308
19.7M
    length+=count;
309
19.7M
    end=p+1;
310
19.7M
  }
311
13.3k
  if (*end != '\0')
312
0
    (void) ThrowMagickException(exception,GetMagickModule(),CoderWarning,
313
0
      "LabelTruncated","`%g'",(double) max_length);
314
13.3k
  destination=(char *) NULL;
315
13.3k
  if (~length >= (MagickPathExtent-1))
316
13.3k
    destination=(char *) AcquireQuantumMemory(length+MagickPathExtent,
317
13.3k
      sizeof(*destination));
318
13.3k
  if (destination == (char *) NULL)
319
13.3k
    ThrowFatalException(ResourceLimitFatalError,"UnableToEscapeString");
320
13.3k
  *destination='\0';
321
13.3k
  q=destination;
322
19.7M
  for (p=source; p < end; p++)
323
19.7M
  {
324
19.7M
    if ((*p == '\\') || (*p == '(') || (*p == ')'))
325
7.86M
      *q++='\\';
326
19.7M
    *q++=(*p);
327
19.7M
  }
328
13.3k
  *q='\0';
329
13.3k
  return(destination);
330
13.3k
}
Unexecuted instantiation: pdf.c:EscapeParenthesis
Unexecuted instantiation: ps2.c:EscapeParenthesis
Unexecuted instantiation: ps3.c:EscapeParenthesis
Unexecuted instantiation: ps.c:EscapeParenthesis
Unexecuted instantiation: xps.c:EscapeParenthesis
331
332
#endif