5172
|
1 |
/***************************************************************************/
|
|
2 |
/* */
|
|
3 |
/* gxvmorx.c */
|
|
4 |
/* */
|
|
5 |
/* TrueTypeGX/AAT morx table validation (body). */
|
|
6 |
/* */
|
|
7 |
/* Copyright 2005, 2008 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 "gxvmorx.h"
|
|
29 |
|
|
30 |
|
|
31 |
/*************************************************************************/
|
|
32 |
/* */
|
|
33 |
/* The macro FT_COMPONENT is used in trace mode. It is an implicit */
|
|
34 |
/* parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log */
|
|
35 |
/* messages during execution. */
|
|
36 |
/* */
|
|
37 |
#undef FT_COMPONENT
|
|
38 |
#define FT_COMPONENT trace_gxvmorx
|
|
39 |
|
|
40 |
|
|
41 |
static void
|
|
42 |
gxv_morx_subtables_validate( FT_Bytes table,
|
|
43 |
FT_Bytes limit,
|
|
44 |
FT_UShort nSubtables,
|
|
45 |
GXV_Validator valid )
|
|
46 |
{
|
|
47 |
FT_Bytes p = table;
|
|
48 |
|
|
49 |
GXV_Validate_Func fmt_funcs_table[] =
|
|
50 |
{
|
|
51 |
gxv_morx_subtable_type0_validate, /* 0 */
|
|
52 |
gxv_morx_subtable_type1_validate, /* 1 */
|
|
53 |
gxv_morx_subtable_type2_validate, /* 2 */
|
|
54 |
NULL, /* 3 */
|
|
55 |
gxv_morx_subtable_type4_validate, /* 4 */
|
|
56 |
gxv_morx_subtable_type5_validate, /* 5 */
|
|
57 |
|
|
58 |
};
|
|
59 |
|
|
60 |
GXV_Validate_Func func;
|
|
61 |
|
|
62 |
FT_UShort i;
|
|
63 |
|
|
64 |
|
|
65 |
GXV_NAME_ENTER( "subtables in a chain" );
|
|
66 |
|
|
67 |
for ( i = 0; i < nSubtables; i++ )
|
|
68 |
{
|
|
69 |
FT_ULong length;
|
|
70 |
FT_ULong coverage;
|
|
71 |
FT_ULong subFeatureFlags;
|
|
72 |
FT_ULong type;
|
|
73 |
FT_ULong rest;
|
|
74 |
|
|
75 |
|
|
76 |
GXV_LIMIT_CHECK( 4 + 4 + 4 );
|
|
77 |
length = FT_NEXT_ULONG( p );
|
|
78 |
coverage = FT_NEXT_ULONG( p );
|
|
79 |
subFeatureFlags = FT_NEXT_ULONG( p );
|
|
80 |
|
|
81 |
GXV_TRACE(( "validating chain subtable %d/%d (%d bytes)\n",
|
|
82 |
i + 1, nSubtables, length ));
|
|
83 |
|
|
84 |
type = coverage & 0x0007;
|
|
85 |
rest = length - ( 4 + 4 + 4 );
|
|
86 |
GXV_LIMIT_CHECK( rest );
|
|
87 |
|
|
88 |
/* morx coverage consists of mort_coverage & 16bit padding */
|
|
89 |
gxv_mort_coverage_validate( (FT_UShort)( ( coverage >> 16 ) | coverage ),
|
|
90 |
valid );
|
|
91 |
if ( type > 5 )
|
|
92 |
FT_INVALID_FORMAT;
|
|
93 |
|
|
94 |
func = fmt_funcs_table[type];
|
|
95 |
if ( func == NULL )
|
|
96 |
GXV_TRACE(( "morx type %d is reserved\n", type ));
|
|
97 |
|
|
98 |
func( p, p + rest, valid );
|
|
99 |
|
|
100 |
p += rest;
|
|
101 |
}
|
|
102 |
|
|
103 |
valid->subtable_length = p - table;
|
|
104 |
|
|
105 |
GXV_EXIT;
|
|
106 |
}
|
|
107 |
|
|
108 |
|
|
109 |
static void
|
|
110 |
gxv_morx_chain_validate( FT_Bytes table,
|
|
111 |
FT_Bytes limit,
|
|
112 |
GXV_Validator valid )
|
|
113 |
{
|
|
114 |
FT_Bytes p = table;
|
|
115 |
FT_ULong defaultFlags;
|
|
116 |
FT_ULong chainLength;
|
|
117 |
FT_ULong nFeatureFlags;
|
|
118 |
FT_ULong nSubtables;
|
|
119 |
|
|
120 |
|
|
121 |
GXV_NAME_ENTER( "morx chain header" );
|
|
122 |
|
|
123 |
GXV_LIMIT_CHECK( 4 + 4 + 4 + 4 );
|
|
124 |
defaultFlags = FT_NEXT_ULONG( p );
|
|
125 |
chainLength = FT_NEXT_ULONG( p );
|
|
126 |
nFeatureFlags = FT_NEXT_ULONG( p );
|
|
127 |
nSubtables = FT_NEXT_ULONG( p );
|
|
128 |
|
|
129 |
/* feature-array of morx is same with that of mort */
|
|
130 |
gxv_mort_featurearray_validate( p, limit, nFeatureFlags, valid );
|
|
131 |
p += valid->subtable_length;
|
|
132 |
|
|
133 |
if ( nSubtables >= 0x10000L )
|
|
134 |
FT_INVALID_DATA;
|
|
135 |
|
|
136 |
gxv_morx_subtables_validate( p, table + chainLength,
|
|
137 |
(FT_UShort)nSubtables, valid );
|
|
138 |
|
|
139 |
valid->subtable_length = chainLength;
|
|
140 |
|
|
141 |
GXV_EXIT;
|
|
142 |
}
|
|
143 |
|
|
144 |
|
|
145 |
FT_LOCAL_DEF( void )
|
|
146 |
gxv_morx_validate( FT_Bytes table,
|
|
147 |
FT_Face face,
|
|
148 |
FT_Validator ftvalid )
|
|
149 |
{
|
|
150 |
GXV_ValidatorRec validrec;
|
|
151 |
GXV_Validator valid = &validrec;
|
|
152 |
FT_Bytes p = table;
|
|
153 |
FT_Bytes limit = 0;
|
|
154 |
FT_ULong version;
|
|
155 |
FT_ULong nChains;
|
|
156 |
FT_ULong i;
|
|
157 |
|
|
158 |
|
|
159 |
valid->root = ftvalid;
|
|
160 |
valid->face = face;
|
|
161 |
|
|
162 |
FT_TRACE3(( "validating `morx' table\n" ));
|
|
163 |
GXV_INIT;
|
|
164 |
|
|
165 |
GXV_LIMIT_CHECK( 4 + 4 );
|
|
166 |
version = FT_NEXT_ULONG( p );
|
|
167 |
nChains = FT_NEXT_ULONG( p );
|
|
168 |
|
|
169 |
if ( version != 0x00020000UL )
|
|
170 |
FT_INVALID_FORMAT;
|
|
171 |
|
|
172 |
for ( i = 0; i < nChains; i++ )
|
|
173 |
{
|
|
174 |
GXV_TRACE(( "validating chain %d/%d\n", i + 1, nChains ));
|
|
175 |
GXV_32BIT_ALIGNMENT_VALIDATE( p - table );
|
|
176 |
gxv_morx_chain_validate( p, limit, valid );
|
|
177 |
p += valid->subtable_length;
|
|
178 |
}
|
|
179 |
|
|
180 |
FT_TRACE4(( "\n" ));
|
|
181 |
}
|
|
182 |
|
|
183 |
|
|
184 |
/* END */
|