update for HEAD-2003050101
[reactos.git] / lib / freetype / src / otlayout / otlgdef.c
1 #include "otlgdef.h"
2 #include "otlcommn.h"
3
4  /************************************************************************/
5  /************************************************************************/
6  /*****                                                              *****/
7  /*****                      ATTACHMENTS LIST                        *****/
8  /*****                                                              *****/
9  /************************************************************************/
10  /************************************************************************/
11
12   static void
13   otl_attach_point_validate( OTL_Bytes      table,
14                              OTL_Validator  valid )
15   {
16     OTL_Bytes  p = table;
17     OTL_UInt   count;
18
19     if ( p + 2 > valid->limit )
20       OTL_INVALID_TOO_SHORT;
21
22     count = OTL_NEXT_USHORT( p );
23     if ( table + count*2 > valid->limit )
24       OTL_INVALID_TOO_SHORT;
25   }
26
27
28   static void
29   otl_attach_list_validate( OTL_Bytes      table,
30                             OTL_Validator  valid )
31   {
32     OTL_Bytes  p = table;
33     OTL_Bytes  coverage;
34     OTL_UInt   count;
35
36     if ( p + 4 > valid->limit )
37       OTL_INVALID_TOO_SHORT;
38
39     coverage = table + OTL_NEXT_USHORT( p );
40     count    = OTL_NEXT_USHORT( p );
41
42     otl_coverage_validate( coverage, valid );
43     if ( count != otl_coverage_get_count( coverage ) )
44       OTL_INVALID_DATA;
45
46     if ( p + count*2 > valid->limit )
47       OTL_INVALID_TOO_SHORT;
48
49     for ( ; count > 0; count-- )
50       otl_attach_point_validate( table + OTL_NEXT_USHORT( p ) );
51   }
52
53
54  /************************************************************************/
55  /************************************************************************/
56  /*****                                                              *****/
57  /*****                      LIGATURE CARETS                         *****/
58  /*****                                                              *****/
59  /************************************************************************/
60  /************************************************************************/
61
62   static void
63   otl_caret_value_validate( OTL_Bytes      table,
64                             OTL_Validator  valid )
65   {
66     OTL_Bytes  p = table;
67
68     if ( p + 4 > valid->limit )
69       OTL_INVALID_TOO_SHORT;
70
71     format = OTL_NEXT_USHORT( p );
72     switch ( format )
73     {
74       case 1:
75       case 2:
76         break;
77
78       case 3:
79         {
80           OTL_Bytes  device;
81
82           p += 2;
83           if ( p + 2 > valid->limit )
84             OTL_INVALID_TOO_SHORT;
85
86           otl_device_table_validate( table + OTL_PEEK_USHORT( p ) );
87         }
88         break;
89
90       default:
91         OTL_INVALID_DATA;
92     }
93   }
94
95
96   static void
97   otl_ligature_glyph_validate( OTL_Bytes      table,
98                                OTL_Validator  valid )
99   {
100     OTL_Bytes  p = table;
101     OTL_UInt   count;
102
103     if ( p + 2 > valid->limit )
104       OTL_INVALID_TOO_SHORT;
105
106     count = OTL_NEXT_USHORT( p );
107
108     if ( p + count*2 > valid->limit )
109       OTL_INVALID_TOO_SHORT;
110
111     for ( ; count > 0; count-- )
112       otl_caret_value_validate( table + OTL_NEXT_USHORT( p ) );
113   }
114
115
116   static void
117   otl_ligature_caret_list_validate( OTL_Bytes      table,
118                                     OTL_Validator  valid )
119   {
120     OTL_Bytes  p = table;
121     OTL_Bytes  coverage;
122     OTL_UInt   count;
123
124     if ( p + 4 > valid->limit )
125       OTL_INVALID_TOO_SHORT;
126
127     coverage = table + OTL_NEXT_USHORT( p );
128     count    = OTL_NEXT_USHORT( p );
129
130     otl_coverage_validate( coverage, valid );
131     if ( count != otl_coverage_get_count( coverage ) )
132       OTL_INVALID_DATA;
133
134     if ( p + count*2 > valid->limit )
135       OTL_INVALID_TOO_SHORT;
136
137     for ( ; count > 0; count-- )
138       otl_ligature_glyph_validate( table + OTL_NEXT_USHORT( p ) );
139   }
140
141
142  /************************************************************************/
143  /************************************************************************/
144  /*****                                                              *****/
145  /*****                         GDEF TABLE                           *****/
146  /*****                                                              *****/
147  /************************************************************************/
148  /************************************************************************/
149
150   OTL_APIDEF( void )
151   otl_gdef_validate( OTL_Bytes      table,
152                      OTL_Validator  valid )
153   {
154     OTL_Bytes  p = table;
155
156     if ( p + 12 > valid->limit )
157       OTL_INVALID_TOO_SHORT;
158
159     /* check format */
160     if ( OTL_NEXT_ULONG( p ) != 0x00010000UL )
161       OTL_INVALID_FORMAT;
162
163     /* validate class definition table */
164     otl_class_definition_validate( table + OTL_NEXT_USHORT( p ) );
165
166     /* validate attachment point list */
167     otl_attach_list_validate( table + OTL_NEXT_USHORT( p ) );
168
169     /* validate ligature caret list */
170     otl_ligature_caret_list_validate( table + OTL_NEXT_USHORT( p ) );
171
172     /* validate mark attach class */
173     otl_class_definition_validate( table + OTL_NEXT_USHORT( p ) );
174   }
175