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
,
106 GXV_NAME_ENTER( "trackTable" );
108 GXV_TRAK_DATA( trackValueOffset_min
) = 0xFFFFU
;
109 GXV_TRAK_DATA( trackValueOffset_max
) = 0x0000;
111 for ( i
= 0; i
< nTracks
; i
++ )
113 GXV_LIMIT_CHECK( 4 + 2 + 2 );
114 track
= FT_NEXT_LONG( p
);
115 nameIndex
= FT_NEXT_USHORT( p
);
116 offset
= FT_NEXT_USHORT( p
);
118 if ( offset
< GXV_TRAK_DATA( trackValueOffset_min
) )
119 GXV_TRAK_DATA( trackValueOffset_min
) = offset
;
120 if ( offset
> GXV_TRAK_DATA( trackValueOffset_max
) )
121 GXV_TRAK_DATA( trackValueOffset_max
) = offset
;
123 gxv_sfntName_validate( nameIndex
, 256, 32767, valid
);
126 valid
->subtable_length
= p
- table
;
132 gxv_trak_trackData_validate( FT_Bytes table
,
134 GXV_Validator valid
)
139 FT_ULong sizeTableOffset
;
141 GXV_ODTECT( 4, odtect
);
144 GXV_ODTECT_INIT( odtect
);
145 GXV_NAME_ENTER( "trackData" );
147 /* read the header of trackData */
148 GXV_LIMIT_CHECK( 2 + 2 + 4 );
149 nTracks
= FT_NEXT_USHORT( p
);
150 nSizes
= FT_NEXT_USHORT( p
);
151 sizeTableOffset
= FT_NEXT_ULONG( p
);
153 gxv_odtect_add_range( table
, p
- table
, "trackData header", odtect
);
155 /* validate trackTable */
156 gxv_trak_trackTable_validate( p
, limit
, nTracks
, valid
);
157 gxv_odtect_add_range( p
, valid
->subtable_length
,
158 "trackTable", odtect
);
160 /* sizeTable is array of FT_Fixed, don't check contents */
161 p
= valid
->root
->base
+ sizeTableOffset
;
162 GXV_LIMIT_CHECK( nSizes
* 4 );
163 gxv_odtect_add_range( p
, nSizes
* 4, "sizeTable", odtect
);
165 /* validate trackValueOffet */
166 p
= valid
->root
->base
+ GXV_TRAK_DATA( trackValueOffset_min
);
167 if ( limit
- p
< nTracks
* nSizes
* 2 )
168 GXV_TRACE(( "too short trackValue array\n" ));
170 p
= valid
->root
->base
+ GXV_TRAK_DATA( trackValueOffset_max
);
171 GXV_LIMIT_CHECK( nSizes
* 2 );
173 gxv_odtect_add_range( valid
->root
->base
174 + GXV_TRAK_DATA( trackValueOffset_min
),
175 GXV_TRAK_DATA( trackValueOffset_max
)
176 - GXV_TRAK_DATA( trackValueOffset_min
)
178 "trackValue array", odtect
);
180 gxv_odtect_validate( odtect
, valid
);
186 /*************************************************************************/
187 /*************************************************************************/
189 /***** trak TABLE *****/
191 /*************************************************************************/
192 /*************************************************************************/
195 gxv_trak_validate( FT_Bytes table
,
197 FT_Validator ftvalid
)
201 FT_Offset table_size
;
203 GXV_ValidatorRec validrec
;
204 GXV_Validator valid
= &validrec
;
205 GXV_trak_DataRec trakrec
;
206 GXV_trak_Data trak
= &trakrec
;
210 FT_UShort horizOffset
;
211 FT_UShort vertOffset
;
215 GXV_ODTECT( 3, odtect
);
217 GXV_ODTECT_INIT( odtect
);
218 valid
->root
= ftvalid
;
219 valid
->table_data
= trak
;
222 limit
= valid
->root
->limit
;
223 table_size
= limit
- table
;
225 FT_TRACE3(( "validating `trak' table\n" ));
228 GXV_LIMIT_CHECK( 4 + 2 + 2 + 2 + 2 );
229 version
= FT_NEXT_ULONG( p
);
230 format
= FT_NEXT_USHORT( p
);
231 horizOffset
= FT_NEXT_USHORT( p
);
232 vertOffset
= FT_NEXT_USHORT( p
);
233 reserved
= FT_NEXT_USHORT( p
);
235 GXV_TRACE(( " (version = 0x%08x)\n", version
));
236 GXV_TRACE(( " (format = 0x%04x)\n", format
));
237 GXV_TRACE(( " (horizOffset = 0x%04x)\n", horizOffset
));
238 GXV_TRACE(( " (vertOffset = 0x%04x)\n", vertOffset
));
239 GXV_TRACE(( " (reserved = 0x%04x)\n", reserved
));
241 /* Version 1.0 (always:1996) */
242 if ( version
!= 0x00010000UL
)
245 /* format 0 (always:1996) */
246 if ( format
!= 0x0000 )
249 GXV_32BIT_ALIGNMENT_VALIDATE( horizOffset
);
250 GXV_32BIT_ALIGNMENT_VALIDATE( vertOffset
);
252 /* Reserved Fixed Value (always) */
253 if ( reserved
!= 0x0000 )
256 /* validate trackData */
257 if ( 0 < horizOffset
)
259 gxv_trak_trackData_validate( table
+ horizOffset
, limit
, valid
);
260 gxv_odtect_add_range( table
+ horizOffset
, valid
->subtable_length
,
261 "horizJustData", odtect
);
264 if ( 0 < vertOffset
)
266 gxv_trak_trackData_validate( table
+ vertOffset
, limit
, valid
);
267 gxv_odtect_add_range( table
+ vertOffset
, valid
->subtable_length
,
268 "vertJustData", odtect
);
271 gxv_odtect_validate( odtect
, valid
);