zenilib: zenilib/jni/external/freetype2/src/gxvalid/gxvfeat.c Source File

zenilib 0.5.3.0

- Main Page
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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, 2005, 2008, 2012 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 {
53 FT_UInt reserved_size;
54 FT_UShort feature;
55 FT_UShort setting;
56
57 } GXV_feat_DataRec, *GXV_feat_Data;
58
59
60 #define GXV_FEAT_DATA( field ) GXV_TABLE_DATA( feat, field )
61
62
63 typedef enum GXV_FeatureFlagsMask_
64 {
65 GXV_FEAT_MASK_EXCLUSIVE_SETTINGS = 0x8000U,
66 GXV_FEAT_MASK_DYNAMIC_DEFAULT = 0x4000,
67 GXV_FEAT_MASK_UNUSED = 0x3F00,
68 GXV_FEAT_MASK_DEFAULT_SETTING = 0x00FF
69
70 } GXV_FeatureFlagsMask;
71
72
73 /*************************************************************************/
74 /*************************************************************************/
75 /***** *****/
76 /***** UTILITY FUNCTIONS *****/
77 /***** *****/
78 /*************************************************************************/
79 /*************************************************************************/
80
81 static void
82 gxv_feat_registry_validate( FT_UShort feature,
83 FT_UShort nSettings,
84 FT_Bool exclusive,
85 GXV_Validator valid )
86 {
87 GXV_NAME_ENTER( "feature in registry" );
88
89 GXV_TRACE(( " (feature = %u)\n", feature ));
90
91 if ( feature >= gxv_feat_registry_length )
92 {
93 GXV_TRACE(( "feature number %d is out of range %d\n",
94 feature, gxv_feat_registry_length ));
95 GXV_SET_ERR_IF_PARANOID( FT_INVALID_DATA );
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 ));
103 GXV_SET_ERR_IF_PARANOID( FT_INVALID_DATA );
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 ( valid->root->level >= FT_VALIDATE_TIGHT )
112 FT_INVALID_DATA;
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 ( valid->root->level >= FT_VALIDATE_TIGHT )
121 FT_INVALID_DATA;
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 ( valid->root->level >= FT_VALIDATE_TIGHT )
129 FT_INVALID_DATA;
130 }
131
132 Exit:
133 GXV_EXIT;
134 }
135
136
137 static void
138 gxv_feat_name_index_validate( FT_Bytes table,
139 FT_Bytes limit,
140 GXV_Validator valid )
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 valid );
157
158 GXV_EXIT;
159 }
160
161
162 static void
163 gxv_feat_setting_validate( FT_Bytes table,
164 FT_Bytes limit,
165 FT_Bool exclusive,
166 GXV_Validator valid )
167 {
168 FT_Bytes p = table;
169 FT_UShort setting;
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 )
180 FT_INVALID_DATA;
181
182 gxv_feat_name_index_validate( p, limit, valid );
183
184 GXV_FEAT_DATA( setting ) = setting;
185
186 GXV_EXIT;
187 }
188
189
190 static void
191 gxv_feat_name_validate( FT_Bytes table,
192 FT_Bytes limit,
193 GXV_Validator valid )
194 {
195 FT_Bytes p = table;
196 FT_UInt reserved_size = GXV_FEAT_DATA( reserved_size );
197
198 FT_UShort feature;
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 );
214 GXV_FEAT_DATA( feature ) = feature;
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 )
221 FT_INVALID_OFFSET;
222
223 if ( ( featureFlags & GXV_FEAT_MASK_UNUSED ) == 0 )
224 GXV_SET_ERR_IF_PARANOID( FT_INVALID_DATA );
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 &
234 GXV_FEAT_MASK_DEFAULT_SETTING );
235 else
236 dynamic_default = 0;
237
238 /* If exclusive, check whether default setting is in the range. */
239 if ( !( dynamic_default < nSettings ) )
240 FT_INVALID_FORMAT;
241 }
242
243 gxv_feat_registry_validate( feature, nSettings, exclusive, valid );
244
245 gxv_feat_name_index_validate( p, limit, valid );
246
247 p = valid->root->base + settingTable;
248 for ( last_setting = -1, i = 0; i < nSettings; i++ )
249 {
250 gxv_feat_setting_validate( p, limit, exclusive, valid );
251
252 if ( (FT_Int)GXV_FEAT_DATA( setting ) <= last_setting )
253 GXV_SET_ERR_IF_PARANOID( FT_INVALID_FORMAT );
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 )
273 gxv_feat_validate( FT_Bytes table,
274 FT_Face face,
275 FT_Validator ftvalid )
276 {
277 GXV_ValidatorRec validrec;
278 GXV_Validator valid = &validrec;
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 valid->root = ftvalid;
293 valid->table_data = feat;
294 valid->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 */
306 FT_INVALID_FORMAT;
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 )
316 FT_INVALID_DATA;
317
318 if ( FT_NEXT_ULONG( p ) != 0 )
319 FT_INVALID_DATA;
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, valid );
327
328 if ( (FT_Int)GXV_FEAT_DATA( feature ) <= last_feature )
329 GXV_SET_ERR_IF_PARANOID( FT_INVALID_FORMAT );
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 */
GXV_FEAT_MASK_EXCLUSIVE_SETTINGS
Definition: gxvfeat.c:65
table
GLenum GLsizei GLenum GLenum const GLvoid * table
Definition: glew.h:4422
FT_ULong
unsigned long FT_ULong
Definition: fttypes.h:249
gxv_feat_registry_validate
static void gxv_feat_registry_validate(FT_UShort feature, FT_UShort nSettings, FT_Bool exclusive, GXV_Validator valid)
Definition: gxvfeat.c:82
FT_INVALID_FORMAT
#define FT_INVALID_FORMAT
Definition: ftvalid.h:133
GXV_NAME_ENTER
#define GXV_NAME_ENTER(name)
Definition: gxvcommn.h:301
FT_Int
signed int FT_Int
Definition: fttypes.h:216
GXV_TRACE
#define GXV_TRACE(s)
Definition: gxvcommn.h:304
GXV_FEAT_MASK_UNUSED
Definition: gxvfeat.c:67
GXV_ValidatorRec_::face
FT_Face face
Definition: gxvcommn.h:241
gxvalid.h
gxv_feat_registry_length
#define gxv_feat_registry_length
Definition: gxvfeat.h:54
gxv_feat_name_index_validate
static void gxv_feat_name_index_validate(FT_Bytes table, FT_Bytes limit, GXV_Validator valid)
Definition: gxvfeat.c:138
gxv_feat_setting_validate
static void gxv_feat_setting_validate(FT_Bytes table, FT_Bytes limit, FT_Bool exclusive, GXV_Validator valid)
Definition: gxvfeat.c:163
GXV_ValidatorRec_::table_data
void * table_data
Definition: gxvcommn.h:242
FT_Bool
FT_BEGIN_HEADER typedef unsigned char FT_Bool
Definition: fttypes.h:104
GXV_SET_ERR_IF_PARANOID
#define GXV_SET_ERR_IF_PARANOID(err)
Definition: gxvcommn.h:66
FT_Byte
unsigned char FT_Byte
Definition: fttypes.h:150
GXV_feat_DataRec
struct GXV_feat_DataRec_ GXV_feat_DataRec
FT_TRACE4
#define FT_TRACE4(varformat)
Definition: ftdebug.h:161
GXV_FEAT_DATA
#define GXV_FEAT_DATA(field)
Definition: gxvfeat.c:60
gxv_feat_registry
static GX_Feature_RegistryRec gxv_feat_registry[]
Definition: gxvfeat.h:59
GXV_EXIT
#define GXV_EXIT
Definition: gxvcommn.h:302
gxv_feat_validate
FT_BEGIN_HEADER gxv_feat_validate(FT_Bytes table, FT_Face face, FT_Validator valid)
Definition: gxvfeat.c:273
FT_LOCAL_DEF
#define FT_LOCAL_DEF(x)
Definition: ftconfig.h:467
FT_FaceRec_
Definition: freetype.h:912
face
GLenum face
Definition: gl2ext.h:1490
p
GLfloat GLfloat p
Definition: glew.h:14938
gxv_sfntName_validate
gxv_sfntName_validate(FT_UShort name_index, FT_UShort min_index, FT_UShort max_index, GXV_Validator valid)
Definition: gxvcommn.c:885
FT_Validator
typedefFT_BEGIN_HEADER struct FT_ValidatorRec_ volatile * FT_Validator
Definition: ftvalid.h:42
limit
GLint limit
Definition: glew.h:11829
FT_Bytes
const FT_Byte * FT_Bytes
Definition: fttypes.h:161
FT_VALIDATE_TIGHT
Definition: ftvalid.h:73
FT_Short
signed short FT_Short
Definition: fttypes.h:194
FT_BOOL
#define FT_BOOL(x)
Definition: fttypes.h:581
FT_NEXT_USHORT
#define FT_NEXT_USHORT(buffer)
Definition: ftstream.h:233
GXV_FEAT_MASK_DEFAULT_SETTING
Definition: gxvfeat.c:68
GXV_FeatureFlagsMask
enum GXV_FeatureFlagsMask_ GXV_FeatureFlagsMask
GXV_FeatureFlagsMask_
GXV_FeatureFlagsMask_
Definition: gxvfeat.c:63
FT_TRACE3
#define FT_TRACE3(varformat)
Definition: ftdebug.h:160
FT_INVALID_OFFSET
#define FT_INVALID_OFFSET
Definition: ftvalid.h:129
IS_PARANOID_VALIDATION
#define IS_PARANOID_VALIDATION
Definition: gxvcommn.h:65
GXV_FEAT_MASK_DYNAMIC_DEFAULT
Definition: gxvfeat.c:66
FT_UInt
unsigned int FT_UInt
Definition: fttypes.h:227
FT_NEXT_ULONG
#define FT_NEXT_ULONG(buffer)
Definition: ftstream.h:245
GXV_ValidatorRec_::root
FT_Validator root
Definition: gxvcommn.h:239
gxvfeat.h
FT_INVALID_DATA
#define FT_INVALID_DATA
Definition: ftvalid.h:141
i
int i
Definition: pngrutil.c:1377
gxvcommn.h
FT_NEXT_SHORT
#define FT_NEXT_SHORT(buffer)
Definition: ftstream.h:230
gxv_feat_name_validate
static void gxv_feat_name_validate(FT_Bytes table, FT_Bytes limit, GXV_Validator valid)
Definition: gxvfeat.c:191
FT_UShort
unsigned short FT_UShort
Definition: fttypes.h:205
GXV_INIT
#define GXV_INIT
Definition: gxvcommn.h:300
GXV_ValidatorRec_
Definition: gxvcommn.h:237
GXV_LIMIT_CHECK
#define GXV_LIMIT_CHECK(_count)
Definition: gxvcommn.h:272
GXV_feat_Data
struct GXV_feat_DataRec_ * GXV_feat_Data