1 /***************************************************************************/
5 /* TrueTypeGX/AAT trak table validation (body). */
7 /* Copyright 2004, 2005 by suzuki toshiya, Masatake YAMATO, Red Hat K.K., */
8 /* David Turner, Robert Wilhelm, and Werner Lemberg. */
10 /* This file is part of the FreeType project, and may only be used, */
11 /* modified, and distributed under the terms of the FreeType project */
12 /* license, LICENSE.TXT. By continuing to use, modify, or distribute */
13 /* this file you indicate that you have read the license and */
14 /* understand and accept it fully. */
16 /***************************************************************************/
18 /***************************************************************************/
20 /* gxvalid is derived from both gxlayout module and otvalid module. */
21 /* Development of gxlayout is supported by the Information-technology */
22 /* Promotion Agency(IPA), Japan. */
24 /***************************************************************************/
31 /*************************************************************************/
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. */
38 #define FT_COMPONENT trace_gxvtrak
41 /*************************************************************************/
42 /*************************************************************************/
44 /***** Data and Types *****/
46 /*************************************************************************/
47 /*************************************************************************/
50 * referred track table format specification:
51 * http://developer.apple.com/fonts/TTRefMan/RM06/Chap6trak.html
52 * last update was 1996.
53 * ----------------------------------------------
54 * [MINIMUM HEADER]: GXV_TRAK_SIZE_MIN
55 * version (fixed: 32bit) = 0x00010000
56 * format (uint16: 16bit) = 0 is only defined (1996)
57 * horizOffset (uint16: 16bit)
58 * vertOffset (uint16: 16bit)
59 * reserved (uint16: 16bit) = 0
60 * ----------------------------------------------
64 * trackTable + nTracks * ( 4 + 2 + 2 )
65 * sizeTable + nSizes * 4 )
66 * ----------------------------------------------
69 * trackTable + nTracks * ( 4 + 2 + 2 )
70 * sizeTable + nSizes * 4 )
71 * ----------------------------------------------
73 typedef struct GXV_trak_DataRec_
75 FT_UShort trackValueOffset_min;
76 FT_UShort trackValueOffset_max;
78 } GXV_trak_DataRec, *GXV_trak_Data;
81 #define GXV_TRAK_DATA( FIELD ) GXV_TABLE_DATA( trak, FIELD )
84 /*************************************************************************/
85 /*************************************************************************/
87 /***** UTILITY FUNCTIONS *****/
89 /*************************************************************************/
90 /*************************************************************************/
93 gxv_trak_trackTable_validate( FT_Bytes table,
96 GXV_Validator gxvalid )
106 GXV_NAME_ENTER( "trackTable" );
108 GXV_TRAK_DATA( trackValueOffset_min ) = 0xFFFFU;
109 GXV_TRAK_DATA( trackValueOffset_max ) = 0x0000;
111 GXV_LIMIT_CHECK( nTracks * ( 4 + 2 + 2 ) );
113 for ( i = 0; i < nTracks; i ++ )
115 p = table + i * ( 4 + 2 + 2 );
116 track = FT_NEXT_LONG( p );
117 nameIndex = FT_NEXT_USHORT( p );
118 offset = FT_NEXT_USHORT( p );
120 if ( offset < GXV_TRAK_DATA( trackValueOffset_min ) )
121 GXV_TRAK_DATA( trackValueOffset_min ) = offset;
122 if ( offset > GXV_TRAK_DATA( trackValueOffset_max ) )
123 GXV_TRAK_DATA( trackValueOffset_max ) = offset;
125 gxv_sfntName_validate( nameIndex, 256, 32767, gxvalid );
127 for ( j = i; j < nTracks; j ++ )
129 p = table + j * ( 4 + 2 + 2 );
130 t = FT_NEXT_LONG( p );
132 GXV_TRACE(( "duplicated entries found for track value 0x%x\n",
137 gxvalid->subtable_length = p - table;
143 gxv_trak_trackData_validate( FT_Bytes table,
145 GXV_Validator gxvalid )
150 FT_ULong sizeTableOffset;
152 GXV_ODTECT( 4, odtect );
155 GXV_ODTECT_INIT( odtect );
156 GXV_NAME_ENTER( "trackData" );
158 /* read the header of trackData */
159 GXV_LIMIT_CHECK( 2 + 2 + 4 );
160 nTracks = FT_NEXT_USHORT( p );
161 nSizes = FT_NEXT_USHORT( p );
162 sizeTableOffset = FT_NEXT_ULONG( p );
164 gxv_odtect_add_range( table, p - table, "trackData header", odtect );
166 /* validate trackTable */
167 gxv_trak_trackTable_validate( p, limit, nTracks, gxvalid );
168 gxv_odtect_add_range( p, gxvalid->subtable_length,
169 "trackTable", odtect );
171 /* sizeTable is array of FT_Fixed, don't check contents */
172 p = gxvalid->root->base + sizeTableOffset;
173 GXV_LIMIT_CHECK( nSizes * 4 );
174 gxv_odtect_add_range( p, nSizes * 4, "sizeTable", odtect );
176 /* validate trackValueOffet */
177 p = gxvalid->root->base + GXV_TRAK_DATA( trackValueOffset_min );
178 if ( limit - p < nTracks * nSizes * 2 )
179 GXV_TRACE(( "too short trackValue array\n" ));
181 p = gxvalid->root->base + GXV_TRAK_DATA( trackValueOffset_max );
182 GXV_LIMIT_CHECK( nSizes * 2 );
184 gxv_odtect_add_range( gxvalid->root->base
185 + GXV_TRAK_DATA( trackValueOffset_min ),
186 GXV_TRAK_DATA( trackValueOffset_max )
187 - GXV_TRAK_DATA( trackValueOffset_min )
189 "trackValue array", odtect );
191 gxv_odtect_validate( odtect, gxvalid );
197 /*************************************************************************/
198 /*************************************************************************/
200 /***** trak TABLE *****/
202 /*************************************************************************/
203 /*************************************************************************/
206 gxv_trak_validate( FT_Bytes table,
208 FT_Validator ftvalid )
213 GXV_ValidatorRec gxvalidrec;
214 GXV_Validator gxvalid = &gxvalidrec;
215 GXV_trak_DataRec trakrec;
216 GXV_trak_Data trak = &trakrec;
220 FT_UShort horizOffset;
221 FT_UShort vertOffset;
225 GXV_ODTECT( 3, odtect );
227 GXV_ODTECT_INIT( odtect );
228 gxvalid->root = ftvalid;
229 gxvalid->table_data = trak;
230 gxvalid->face = face;
232 limit = gxvalid->root->limit;
234 FT_TRACE3(( "validating `trak' table\n" ));
237 GXV_LIMIT_CHECK( 4 + 2 + 2 + 2 + 2 );
238 version = FT_NEXT_ULONG( p );
239 format = FT_NEXT_USHORT( p );
240 horizOffset = FT_NEXT_USHORT( p );
241 vertOffset = FT_NEXT_USHORT( p );
242 reserved = FT_NEXT_USHORT( p );
244 GXV_TRACE(( " (version = 0x%08x)\n", version ));
245 GXV_TRACE(( " (format = 0x%04x)\n", format ));
246 GXV_TRACE(( " (horizOffset = 0x%04x)\n", horizOffset ));
247 GXV_TRACE(( " (vertOffset = 0x%04x)\n", vertOffset ));
248 GXV_TRACE(( " (reserved = 0x%04x)\n", reserved ));
250 /* Version 1.0 (always:1996) */
251 if ( version != 0x00010000UL )
254 /* format 0 (always:1996) */
255 if ( format != 0x0000 )
258 GXV_32BIT_ALIGNMENT_VALIDATE( horizOffset );
259 GXV_32BIT_ALIGNMENT_VALIDATE( vertOffset );
261 /* Reserved Fixed Value (always) */
262 if ( reserved != 0x0000 )
265 /* validate trackData */
266 if ( 0 < horizOffset )
268 gxv_trak_trackData_validate( table + horizOffset, limit, gxvalid );
269 gxv_odtect_add_range( table + horizOffset, gxvalid->subtable_length,
270 "horizJustData", odtect );
273 if ( 0 < vertOffset )
275 gxv_trak_trackData_validate( table + vertOffset, limit, gxvalid );
276 gxv_odtect_add_range( table + vertOffset, gxvalid->subtable_length,
277 "vertJustData", odtect );
280 gxv_odtect_validate( odtect, gxvalid );