ReactOS  0.4.15-dev-2701-g34593d9
gxvtrak.c
Go to the documentation of this file.
1 /***************************************************************************/
2 /* */
3 /* gxvtrak.c */
4 /* */
5 /* TrueTypeGX/AAT trak 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 
31 
32  /*************************************************************************/
33  /* */
34  /* The macro FT_COMPONENT is used in trace mode. It is an implicit */
35  /* parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log */
36  /* messages during execution. */
37  /* */
38 #undef FT_COMPONENT
39 #define FT_COMPONENT trace_gxvtrak
40 
41 
42  /*************************************************************************/
43  /*************************************************************************/
44  /***** *****/
45  /***** Data and Types *****/
46  /***** *****/
47  /*************************************************************************/
48  /*************************************************************************/
49 
50  /*
51  * referred track table format specification:
52  * https://developer.apple.com/fonts/TrueType-Reference-Manual/RM06/Chap6trak.html
53  * last update was 1996.
54  * ----------------------------------------------
55  * [MINIMUM HEADER]: GXV_TRAK_SIZE_MIN
56  * version (fixed: 32bit) = 0x00010000
57  * format (uint16: 16bit) = 0 is only defined (1996)
58  * horizOffset (uint16: 16bit)
59  * vertOffset (uint16: 16bit)
60  * reserved (uint16: 16bit) = 0
61  * ----------------------------------------------
62  * [VARIABLE BODY]:
63  * horizData
64  * header ( 2 + 2 + 4
65  * trackTable + nTracks * ( 4 + 2 + 2 )
66  * sizeTable + nSizes * 4 )
67  * ----------------------------------------------
68  * vertData
69  * header ( 2 + 2 + 4
70  * trackTable + nTracks * ( 4 + 2 + 2 )
71  * sizeTable + nSizes * 4 )
72  * ----------------------------------------------
73  */
74  typedef struct GXV_trak_DataRec_
75  {
78 
80 
81 
82 #define GXV_TRAK_DATA( FIELD ) GXV_TABLE_DATA( trak, FIELD )
83 
84 
85  /*************************************************************************/
86  /*************************************************************************/
87  /***** *****/
88  /***** UTILITY FUNCTIONS *****/
89  /***** *****/
90  /*************************************************************************/
91  /*************************************************************************/
92 
93  static void
96  FT_UShort nTracks,
97  GXV_Validator gxvalid )
98  {
99  FT_Bytes p = table;
100 
101  FT_Fixed track, t;
102  FT_UShort nameIndex;
104  FT_UShort i, j;
105 
106 
107  GXV_NAME_ENTER( "trackTable" );
108 
109  GXV_TRAK_DATA( trackValueOffset_min ) = 0xFFFFU;
110  GXV_TRAK_DATA( trackValueOffset_max ) = 0x0000;
111 
112  GXV_LIMIT_CHECK( nTracks * ( 4 + 2 + 2 ) );
113 
114  for ( i = 0; i < nTracks; i++ )
115  {
116  p = table + i * ( 4 + 2 + 2 );
117  track = FT_NEXT_LONG( p );
118  nameIndex = FT_NEXT_USHORT( p );
119  offset = FT_NEXT_USHORT( p );
120 
121  if ( offset < GXV_TRAK_DATA( trackValueOffset_min ) )
122  GXV_TRAK_DATA( trackValueOffset_min ) = offset;
123  if ( offset > GXV_TRAK_DATA( trackValueOffset_max ) )
124  GXV_TRAK_DATA( trackValueOffset_max ) = offset;
125 
126  gxv_sfntName_validate( nameIndex, 256, 32767, gxvalid );
127 
128  for ( j = i; j < nTracks; j++ )
129  {
130  p = table + j * ( 4 + 2 + 2 );
131  t = FT_NEXT_LONG( p );
132  if ( t == track )
133  GXV_TRACE(( "duplicated entries found for track value 0x%x\n",
134  track ));
135  }
136  }
137 
138  gxvalid->subtable_length = (FT_ULong)( p - table );
139  GXV_EXIT;
140  }
141 
142 
143  static void
145  FT_Bytes limit,
146  GXV_Validator gxvalid )
147  {
148  FT_Bytes p = table;
149  FT_UShort nTracks;
150  FT_UShort nSizes;
151  FT_ULong sizeTableOffset;
152 
153  GXV_ODTECT( 4, odtect );
154 
155 
156  GXV_ODTECT_INIT( odtect );
157  GXV_NAME_ENTER( "trackData" );
158 
159  /* read the header of trackData */
160  GXV_LIMIT_CHECK( 2 + 2 + 4 );
161  nTracks = FT_NEXT_USHORT( p );
162  nSizes = FT_NEXT_USHORT( p );
163  sizeTableOffset = FT_NEXT_ULONG( p );
164 
166  "trackData header", odtect );
167 
168  /* validate trackTable */
169  gxv_trak_trackTable_validate( p, limit, nTracks, gxvalid );
171  "trackTable", odtect );
172 
173  /* sizeTable is array of FT_Fixed, don't check contents */
174  p = gxvalid->root->base + sizeTableOffset;
175  GXV_LIMIT_CHECK( nSizes * 4 );
176  gxv_odtect_add_range( p, nSizes * 4, "sizeTable", odtect );
177 
178  /* validate trackValueOffet */
179  p = gxvalid->root->base + GXV_TRAK_DATA( trackValueOffset_min );
180  if ( limit - p < nTracks * nSizes * 2 )
181  GXV_TRACE(( "too short trackValue array\n" ));
182 
183  p = gxvalid->root->base + GXV_TRAK_DATA( trackValueOffset_max );
184  GXV_LIMIT_CHECK( nSizes * 2 );
185 
186  gxv_odtect_add_range( gxvalid->root->base
187  + GXV_TRAK_DATA( trackValueOffset_min ),
188  GXV_TRAK_DATA( trackValueOffset_max )
189  - GXV_TRAK_DATA( trackValueOffset_min )
190  + nSizes * 2,
191  "trackValue array", odtect );
192 
193  gxv_odtect_validate( odtect, gxvalid );
194 
195  GXV_EXIT;
196  }
197 
198 
199  /*************************************************************************/
200  /*************************************************************************/
201  /***** *****/
202  /***** trak TABLE *****/
203  /***** *****/
204  /*************************************************************************/
205  /*************************************************************************/
206 
207  FT_LOCAL_DEF( void )
209  FT_Face face,
210  FT_Validator ftvalid )
211  {
212  FT_Bytes p = table;
213  FT_Bytes limit = 0;
214 
215  GXV_ValidatorRec gxvalidrec;
216  GXV_Validator gxvalid = &gxvalidrec;
217  GXV_trak_DataRec trakrec;
218  GXV_trak_Data trak = &trakrec;
219 
222  FT_UShort horizOffset;
223  FT_UShort vertOffset;
225 
226 
227  GXV_ODTECT( 3, odtect );
228 
229  GXV_ODTECT_INIT( odtect );
230  gxvalid->root = ftvalid;
231  gxvalid->table_data = trak;
232  gxvalid->face = face;
233 
234  limit = gxvalid->root->limit;
235 
236  FT_TRACE3(( "validating `trak' table\n" ));
237  GXV_INIT;
238 
239  GXV_LIMIT_CHECK( 4 + 2 + 2 + 2 + 2 );
240  version = FT_NEXT_ULONG( p );
241  format = FT_NEXT_USHORT( p );
242  horizOffset = FT_NEXT_USHORT( p );
243  vertOffset = FT_NEXT_USHORT( p );
245 
246  GXV_TRACE(( " (version = 0x%08x)\n", version ));
247  GXV_TRACE(( " (format = 0x%04x)\n", format ));
248  GXV_TRACE(( " (horizOffset = 0x%04x)\n", horizOffset ));
249  GXV_TRACE(( " (vertOffset = 0x%04x)\n", vertOffset ));
250  GXV_TRACE(( " (reserved = 0x%04x)\n", reserved ));
251 
252  /* Version 1.0 (always:1996) */
253  if ( version != 0x00010000UL )
255 
256  /* format 0 (always:1996) */
257  if ( format != 0x0000 )
259 
260  GXV_32BIT_ALIGNMENT_VALIDATE( horizOffset );
261  GXV_32BIT_ALIGNMENT_VALIDATE( vertOffset );
262 
263  /* Reserved Fixed Value (always) */
264  if ( reserved != 0x0000 )
266 
267  /* validate trackData */
268  if ( 0 < horizOffset )
269  {
270  gxv_trak_trackData_validate( table + horizOffset, limit, gxvalid );
271  gxv_odtect_add_range( table + horizOffset, gxvalid->subtable_length,
272  "horizJustData", odtect );
273  }
274 
275  if ( 0 < vertOffset )
276  {
277  gxv_trak_trackData_validate( table + vertOffset, limit, gxvalid );
278  gxv_odtect_add_range( table + vertOffset, gxvalid->subtable_length,
279  "vertJustData", odtect );
280  }
281 
282  gxv_odtect_validate( odtect, gxvalid );
283 
284  FT_TRACE4(( "\n" ));
285  }
286 
287 
288 /* END */
unsigned long FT_ULong
Definition: fttypes.h:253
#define FT_NEXT_LONG(buffer)
Definition: ftstream.h:235
static void gxv_trak_trackTable_validate(FT_Bytes table, FT_Bytes limit, FT_UShort nTracks, GXV_Validator gxvalid)
Definition: gxvtrak.c:94
#define FT_INVALID_FORMAT
Definition: ftvalid.h:142
#define GXV_NAME_ENTER(name)
Definition: gxvcommn.h:301
#define GXV_TRACE(s)
Definition: gxvcommn.h:304
#define U(x)
Definition: wordpad.c:45
GLdouble GLdouble t
Definition: gl.h:2047
gxv_trak_validate(FT_Bytes table, FT_Face face, FT_Validator ftvalid)
Definition: gxvtrak.c:208
GLenum GLsizei GLenum GLenum const GLvoid * table
Definition: glext.h:5644
#define GXV_ODTECT(n, odtect)
Definition: gxvcommn.h:562
gxv_sfntName_validate(FT_UShort name_index, FT_UShort min_index, FT_UShort max_index, GXV_Validator gxvalid)
Definition: gxvcommn.c:884
GLint GLint GLsizei GLsizei GLsizei GLint GLenum format
Definition: gl.h:1546
GLint limit
Definition: glext.h:10326
gxv_odtect_validate(GXV_odtect_Range odtect, GXV_Validator gxvalid)
Definition: gxvcommn.c:1715
struct GXV_trak_DataRec_ GXV_trak_DataRec
#define FT_TRACE4(varformat)
Definition: ftdebug.h:161
r reserved
Definition: btrfs.c:2940
void * table_data
Definition: gxvcommn.h:242
static const WCHAR version[]
Definition: asmname.c:66
#define GXV_EXIT
Definition: gxvcommn.h:302
#define FT_LOCAL_DEF(x)
Definition: ftconfig.h:388
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 GLint GLint j
Definition: glfuncs.h:250
FT_Validator root
Definition: gxvcommn.h:239
GLintptr offset
Definition: glext.h:5920
typedefFT_BEGIN_HEADER struct FT_ValidatorRec_ volatile * FT_Validator
Definition: ftvalid.h:42
#define GXV_32BIT_ALIGNMENT_VALIDATE(a)
Definition: gxvcommn.h:317
WORD face[3]
Definition: mesh.c:4747
#define GXV_ODTECT_INIT(odtect)
Definition: gxvcommn.h:567
const FT_Byte * FT_Bytes
Definition: fttypes.h:165
#define GXV_TRAK_DATA(FIELD)
Definition: gxvtrak.c:82
#define FT_NEXT_USHORT(buffer)
Definition: ftstream.h:226
static void gxv_trak_trackData_validate(FT_Bytes table, FT_Bytes limit, GXV_Validator gxvalid)
Definition: gxvtrak.c:144
#define FT_TRACE3(varformat)
Definition: ftdebug.h:160
signed long FT_Fixed
Definition: fttypes.h:288
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
#define FT_NEXT_ULONG(buffer)
Definition: ftstream.h:238
#define FT_INVALID_DATA
Definition: ftvalid.h:150
FT_UShort trackValueOffset_min
Definition: gxvtrak.c:76
FT_ULong subtable_length
Definition: gxvcommn.h:244
gxv_odtect_add_range(FT_Bytes start, FT_ULong length, const FT_String *name, GXV_odtect_Range odtect)
Definition: gxvcommn.c:1702
GLfloat GLfloat p
Definition: glext.h:8902
unsigned short FT_UShort
Definition: fttypes.h:209
#define GXV_INIT
Definition: gxvcommn.h:300
struct GXV_trak_DataRec_ * GXV_trak_Data
GLenum GLuint GLint GLenum face
Definition: glext.h:7025
#define GXV_LIMIT_CHECK(_count)
Definition: gxvcommn.h:272
FT_UShort trackValueOffset_max
Definition: gxvtrak.c:77