ReactOS  0.4.14-dev-342-gdc047f9
gxvfeat.c
Go to the documentation of this file.
1 /***************************************************************************/
2 /* */
3 /* gxvfeat.c */
4 /* */
5 /* TrueTypeGX/AAT feat table validation (body). */
6 /* */
7 /* Copyright 2004-2018 by */
8 /* suzuki toshiya, Masatake YAMATO, Red Hat K.K., */
9 /* David Turner, Robert Wilhelm, and Werner Lemberg. */
10 /* */
11 /* This file is part of the FreeType project, and may only be used, */
12 /* modified, and distributed under the terms of the FreeType project */
13 /* license, LICENSE.TXT. By continuing to use, modify, or distribute */
14 /* this file you indicate that you have read the license and */
15 /* understand and accept it fully. */
16 /* */
17 /***************************************************************************/
18 
19 /***************************************************************************/
20 /* */
21 /* gxvalid is derived from both gxlayout module and otvalid module. */
22 /* Development of gxlayout is supported by the Information-technology */
23 /* Promotion Agency(IPA), Japan. */
24 /* */
25 /***************************************************************************/
26 
27 
28 #include "gxvalid.h"
29 #include "gxvcommn.h"
30 #include "gxvfeat.h"
31 
32 
33  /*************************************************************************/
34  /* */
35  /* The macro FT_COMPONENT is used in trace mode. It is an implicit */
36  /* parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log */
37  /* messages during execution. */
38  /* */
39 #undef FT_COMPONENT
40 #define FT_COMPONENT trace_gxvfeat
41 
42 
43  /*************************************************************************/
44  /*************************************************************************/
45  /***** *****/
46  /***** Data and Types *****/
47  /***** *****/
48  /*************************************************************************/
49  /*************************************************************************/
50 
51  typedef struct GXV_feat_DataRec_
52  {
56 
58 
59 
60 #define GXV_FEAT_DATA( field ) GXV_TABLE_DATA( feat, field )
61 
62 
63  typedef enum GXV_FeatureFlagsMask_
64  {
69 
71 
72 
73  /*************************************************************************/
74  /*************************************************************************/
75  /***** *****/
76  /***** UTILITY FUNCTIONS *****/
77  /***** *****/
78  /*************************************************************************/
79  /*************************************************************************/
80 
81  static void
83  FT_UShort nSettings,
84  FT_Bool exclusive,
85  GXV_Validator gxvalid )
86  {
87  GXV_NAME_ENTER( "feature in registry" );
88 
89  GXV_TRACE(( " (feature = %u)\n", feature ));
90 
92  {
93  GXV_TRACE(( "feature number %d is out of range %d\n",
96  goto Exit;
97  }
98 
99  if ( gxv_feat_registry[feature].existence == 0 )
100  {
101  GXV_TRACE(( "feature number %d is in defined range but doesn't exist\n",
102  feature ));
104  goto Exit;
105  }
106 
107  if ( gxv_feat_registry[feature].apple_reserved )
108  {
109  /* Don't use here. Apple is reserved. */
110  GXV_TRACE(( "feature number %d is reserved by Apple\n", feature ));
111  if ( gxvalid->root->level >= FT_VALIDATE_TIGHT )
113  }
114 
115  if ( nSettings != gxv_feat_registry[feature].nSettings )
116  {
117  GXV_TRACE(( "feature %d: nSettings %d != defined nSettings %d\n",
118  feature, nSettings,
119  gxv_feat_registry[feature].nSettings ));
120  if ( gxvalid->root->level >= FT_VALIDATE_TIGHT )
122  }
123 
124  if ( exclusive != gxv_feat_registry[feature].exclusive )
125  {
126  GXV_TRACE(( "exclusive flag %d differs from predefined value\n",
127  exclusive ));
128  if ( gxvalid->root->level >= FT_VALIDATE_TIGHT )
130  }
131 
132  Exit:
133  GXV_EXIT;
134  }
135 
136 
137  static void
139  FT_Bytes limit,
140  GXV_Validator gxvalid )
141  {
142  FT_Bytes p = table;
143 
144  FT_Short nameIndex;
145 
146 
147  GXV_NAME_ENTER( "nameIndex" );
148 
149  GXV_LIMIT_CHECK( 2 );
150  nameIndex = FT_NEXT_SHORT ( p );
151  GXV_TRACE(( " (nameIndex = %d)\n", nameIndex ));
152 
153  gxv_sfntName_validate( (FT_UShort)nameIndex,
154  255,
155  32768U,
156  gxvalid );
157 
158  GXV_EXIT;
159  }
160 
161 
162  static void
164  FT_Bytes limit,
165  FT_Bool exclusive,
166  GXV_Validator gxvalid )
167  {
168  FT_Bytes p = table;
170 
171 
172  GXV_NAME_ENTER( "setting" );
173 
174  GXV_LIMIT_CHECK( 2 );
175 
176  setting = FT_NEXT_USHORT( p );
177 
178  /* If we have exclusive setting, the setting should be odd. */
179  if ( exclusive && ( setting & 1 ) == 0 )
181 
182  gxv_feat_name_index_validate( p, limit, gxvalid );
183 
185 
186  GXV_EXIT;
187  }
188 
189 
190  static void
192  FT_Bytes limit,
193  GXV_Validator gxvalid )
194  {
195  FT_Bytes p = table;
196  FT_UInt reserved_size = GXV_FEAT_DATA( reserved_size );
197 
199  FT_UShort nSettings;
200  FT_ULong settingTable;
201  FT_UShort featureFlags;
202 
203  FT_Bool exclusive;
204  FT_Int last_setting;
205  FT_UInt i;
206 
207 
208  GXV_NAME_ENTER( "name" );
209 
210  /* feature + nSettings + settingTable + featureFlags */
211  GXV_LIMIT_CHECK( 2 + 2 + 4 + 2 );
212 
213  feature = FT_NEXT_USHORT( p );
215 
216  nSettings = FT_NEXT_USHORT( p );
217  settingTable = FT_NEXT_ULONG ( p );
218  featureFlags = FT_NEXT_USHORT( p );
219 
220  if ( settingTable < reserved_size )
222 
223  if ( ( featureFlags & GXV_FEAT_MASK_UNUSED ) == 0 )
225 
226  exclusive = FT_BOOL( featureFlags & GXV_FEAT_MASK_EXCLUSIVE_SETTINGS );
227  if ( exclusive )
228  {
229  FT_Byte dynamic_default;
230 
231 
232  if ( featureFlags & GXV_FEAT_MASK_DYNAMIC_DEFAULT )
233  dynamic_default = (FT_Byte)( featureFlags &
235  else
236  dynamic_default = 0;
237 
238  /* If exclusive, check whether default setting is in the range. */
239  if ( !( dynamic_default < nSettings ) )
241  }
242 
243  gxv_feat_registry_validate( feature, nSettings, exclusive, gxvalid );
244 
245  gxv_feat_name_index_validate( p, limit, gxvalid );
246 
247  p = gxvalid->root->base + settingTable;
248  for ( last_setting = -1, i = 0; i < nSettings; i++ )
249  {
250  gxv_feat_setting_validate( p, limit, exclusive, gxvalid );
251 
252  if ( (FT_Int)GXV_FEAT_DATA( setting ) <= last_setting )
254 
255  last_setting = (FT_Int)GXV_FEAT_DATA( setting );
256  /* setting + nameIndex */
257  p += ( 2 + 2 );
258  }
259 
260  GXV_EXIT;
261  }
262 
263 
264  /*************************************************************************/
265  /*************************************************************************/
266  /***** *****/
267  /***** feat TABLE *****/
268  /***** *****/
269  /*************************************************************************/
270  /*************************************************************************/
271 
272  FT_LOCAL_DEF( void )
274  FT_Face face,
275  FT_Validator ftvalid )
276  {
277  GXV_ValidatorRec gxvalidrec;
278  GXV_Validator gxvalid = &gxvalidrec;
279 
280  GXV_feat_DataRec featrec;
281  GXV_feat_Data feat = &featrec;
282 
283  FT_Bytes p = table;
284  FT_Bytes limit = 0;
285 
286  FT_UInt featureNameCount;
287 
288  FT_UInt i;
289  FT_Int last_feature;
290 
291 
292  gxvalid->root = ftvalid;
293  gxvalid->table_data = feat;
294  gxvalid->face = face;
295 
296  FT_TRACE3(( "validating `feat' table\n" ));
297  GXV_INIT;
298 
299  feat->reserved_size = 0;
300 
301  /* version + featureNameCount + none_0 + none_1 */
302  GXV_LIMIT_CHECK( 4 + 2 + 2 + 4 );
303  feat->reserved_size += 4 + 2 + 2 + 4;
304 
305  if ( FT_NEXT_ULONG( p ) != 0x00010000UL ) /* Version */
307 
308  featureNameCount = FT_NEXT_USHORT( p );
309  GXV_TRACE(( " (featureNameCount = %d)\n", featureNameCount ));
310 
311  if ( !( IS_PARANOID_VALIDATION ) )
312  p += 6; /* skip (none) and (none) */
313  else
314  {
315  if ( FT_NEXT_USHORT( p ) != 0 )
317 
318  if ( FT_NEXT_ULONG( p ) != 0 )
320  }
321 
322  feat->reserved_size += featureNameCount * ( 2 + 2 + 4 + 2 + 2 );
323 
324  for ( last_feature = -1, i = 0; i < featureNameCount; i++ )
325  {
326  gxv_feat_name_validate( p, limit, gxvalid );
327 
328  if ( (FT_Int)GXV_FEAT_DATA( feature ) <= last_feature )
330 
331  last_feature = GXV_FEAT_DATA( feature );
332  p += 2 + 2 + 4 + 2 + 2;
333  }
334 
335  FT_TRACE4(( "\n" ));
336  }
337 
338 
339 /* END */
INTERNETFEATURELIST feature
Definition: misc.c:1689
unsigned long FT_ULong
Definition: fttypes.h:253
#define FT_INVALID_FORMAT
Definition: ftvalid.h:142
#define GXV_NAME_ENTER(name)
Definition: gxvcommn.h:301
signed int FT_Int
Definition: fttypes.h:220
#define GXV_TRACE(s)
Definition: gxvcommn.h:304
FT_UShort setting
Definition: gxvfeat.c:55
#define U(x)
Definition: wordpad.c:44
static void gxv_feat_name_index_validate(FT_Bytes table, FT_Bytes limit, GXV_Validator gxvalid)
Definition: gxvfeat.c:138
GLenum GLsizei GLenum GLenum const GLvoid * table
Definition: glext.h:5644
WORD face[3]
Definition: mesh.c:4747
#define gxv_feat_registry_length
Definition: gxvfeat.h:55
static void gxv_feat_setting_validate(FT_Bytes table, FT_Bytes limit, FT_Bool exclusive, GXV_Validator gxvalid)
Definition: gxvfeat.c:163
gxv_sfntName_validate(FT_UShort name_index, FT_UShort min_index, FT_UShort max_index, GXV_Validator gxvalid)
Definition: gxvcommn.c:884
GLint limit
Definition: glext.h:10326
gxv_feat_validate(FT_Bytes table, FT_Face face, FT_Validator ftvalid)
Definition: gxvfeat.c:273
FT_BEGIN_HEADER typedef unsigned char FT_Bool
Definition: fttypes.h:108
#define GXV_SET_ERR_IF_PARANOID(err)
Definition: gxvcommn.h:66
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
unsigned char FT_Byte
Definition: fttypes.h:154
struct GXV_feat_DataRec_ GXV_feat_DataRec
#define FT_TRACE4(varformat)
Definition: ftdebug.h:161
FT_UShort feature
Definition: gxvfeat.c:54
void * table_data
Definition: gxvcommn.h:242
#define GXV_FEAT_DATA(field)
Definition: gxvfeat.c:60
static GX_Feature_RegistryRec gxv_feat_registry[]
Definition: gxvfeat.h:60
#define GXV_EXIT
Definition: gxvcommn.h:302
#define FT_LOCAL_DEF(x)
Definition: ftconfig.h:388
FT_Validator root
Definition: gxvcommn.h:239
static void Exit(void)
Definition: sock.c:1331
typedefFT_BEGIN_HEADER struct FT_ValidatorRec_ volatile * FT_Validator
Definition: ftvalid.h:42
const FT_Byte * FT_Bytes
Definition: fttypes.h:165
FT_UInt reserved_size
Definition: gxvfeat.c:53
signed short FT_Short
Definition: fttypes.h:198
static void gxv_feat_registry_validate(FT_UShort feature, FT_UShort nSettings, FT_Bool exclusive, GXV_Validator gxvalid)
Definition: gxvfeat.c:82
#define FT_BOOL(x)
Definition: fttypes.h:578
#define FT_NEXT_USHORT(buffer)
Definition: ftstream.h:226
static void gxv_feat_name_validate(FT_Bytes table, FT_Bytes limit, GXV_Validator gxvalid)
Definition: gxvfeat.c:191
enum GXV_FeatureFlagsMask_ GXV_FeatureFlagsMask
GXV_FeatureFlagsMask_
Definition: gxvfeat.c:63
#define FT_TRACE3(varformat)
Definition: ftdebug.h:160
#define FT_INVALID_OFFSET
Definition: ftvalid.h:138
#define IS_PARANOID_VALIDATION
Definition: gxvcommn.h:65
unsigned int FT_UInt
Definition: fttypes.h:231
#define FT_NEXT_ULONG(buffer)
Definition: ftstream.h:238
#define FT_INVALID_DATA
Definition: ftvalid.h:150
#define FT_NEXT_SHORT(buffer)
Definition: ftstream.h:223
GLfloat GLfloat p
Definition: glext.h:8902
unsigned short FT_UShort
Definition: fttypes.h:209
#define GXV_INIT
Definition: gxvcommn.h:300
GLenum GLuint GLint GLenum face
Definition: glext.h:7025
#define GXV_LIMIT_CHECK(_count)
Definition: gxvcommn.h:272
struct GXV_feat_DataRec_ * GXV_feat_Data