xref: /inferno-os/libfreetype/otlbase.c (revision 37da2899f40661e3e9631e497da8dc59b971cbd0)
1 #include "otlbase.h"
2 #include "otlcommn.h"
3 
4   static void
otl_base_coord_validate(OTL_Bytes table,OTL_Validator valid)5   otl_base_coord_validate( OTL_Bytes      table,
6                            OTL_Validator  valid )
7   {
8     OTL_Bytes  p = table;
9     OTL_UInt   format;
10 
11     OTL_CHECK( 4 );
12 
13     format = OTL_NEXT_USHORT( p );
14     p += 2;
15 
16     switch ( format )
17     {
18       case 1:
19         break;
20 
21       case 2:
22         OTL_CHECK( 4 );
23         break;
24 
25       case 3:
26         OTL_CHECK( 2 );
27         otl_device_table_validate( table + OTL_PEEK_USHORT( p ) );
28         break;
29 
30       default:
31         OTL_INVALID_DATA;
32     }
33   }
34 
35 
36   static void
otl_base_tag_list_validate(OTL_Bytes table,OTL_Validator valid)37   otl_base_tag_list_validate( OTL_Bytes      table,
38                               OTL_Validator  valid )
39   {
40     OTL_Bytes  p = table;
41     OTL_UInt   count;
42 
43     OTL_CHECK(2);
44 
45     count = OTL_NEXT_USHORT( p );
46     OTL_CHECK( count*4 );
47   }
48 
49 
50 
51   static void
otl_base_values_validate(OTL_Bytes table,OTL_Validator valid)52   otl_base_values_validate( OTL_Bytes      table,
53                             OTL_Validator  valid )
54   {
55     OTL_Bytes  p = table;
56     OTL_UInt   count;
57 
58     OTL_CHECK( 4 );
59 
60     p    += 2;  /* skip default index */
61     count = OTL_NEXT_USHORT( p );
62 
63     OTL_CHECK( count*2 );
64 
65     for ( ; count > 0; count-- )
66       otl_base_coord_validate( table + OTL_NEXT_USHORT( p ), valid );
67   }
68 
69 
70   static void
otl_base_minmax_validate(OTL_Bytes table,OTL_Validator valid)71   otl_base_minmax_validate( OTL_Bytes      table,
72                             OTL_Validator  valid )
73   {
74     OTL_Bytes  p = table;
75     OTL_UInt   min_coord, max_coord, count;
76 
77     OTL_CHECK(6);
78     min_coord = OTL_NEXT_USHORT( p );
79     max_coord = OTL_NEXT_USHORT( p );
80     count     = OTL_NEXT_USHORT( p );
81 
82     if ( min_coord )
83       otl_base_coord_validate( table + min_coord, valid );
84 
85     if ( max_coord )
86       otl_base_coord_validate( table + max_coord, valid );
87 
88     OTL_CHECK( count*8 );
89     for ( ; count > 0; count-- )
90     {
91       p += 4;  /* ignore tag */
92       min_coord = OTL_NEXT_USHORT( p );
93       max_coord = OTL_NEXT_USHORT( p );
94 
95       if ( min_coord )
96         otl_base_coord_validate( table + min_coord, valid );
97 
98       if ( max_coord )
99         otl_base_coord_validate( table + max_coord, valid );
100     }
101   }
102 
103 
104   static void
otl_base_script_validate(OTL_Bytes table,OTL_Validator valid)105   otl_base_script_validate( OTL_Bytes      table,
106                             OTL_Validator  valid )
107   {
108     OTL_Bytes  p = table;
109     OTL_UInt   values, default_minmax;
110 
111     OTL_CHECK(6);
112 
113     values         = OTL_NEXT_USHORT( p );
114     default_minmax = OTL_NEXT_USHORT( p );
115     count          = OTL_NEXT_USHORT( p );
116 
117     if ( values )
118       otl_base_values_validate( table + values, valid );
119 
120     if ( default_minmax )
121       otl_base_minmax_validate( table + default_minmax, valid );
122 
123     OTL_CHECK( count*6 );
124     for ( ; count > 0; count-- )
125     {
126       p += 4;  /* ignore tag */
127       otl_base_minmax_validate( table + OTL_NEXT_USHORT( p ), valid );
128     }
129   }
130 
131 
132   static void
otl_base_script_list_validate(OTL_Bytes table,OTL_Validator valid)133   otl_base_script_list_validate( OTL_Bytes      table,
134                                  OTL_Validator  valid )
135   {
136     OTL_Bytes  p = table;
137     OTL_UInt   count;
138 
139     OTL_CHECK(2);
140 
141     count = OTL_NEXT_USHORT( p );
142     OTL_CHECK(count*6);
143 
144     for ( ; count > 0; count-- )
145     {
146       p += 4;  /* ignore script tag */
147       otl_base_script_validate( table + OTL_NEXT_USHORT( p ) );
148     }
149   }
150 
151   static void
otl_axis_table_validate(OTL_Bytes table,OTL_Validator valid)152   otl_axis_table_validate( OTL_Bytes      table,
153                            OTL_Validator  valid )
154   {
155     OTL_Bytes  p = table;
156     OTL_UInt   tags;
157 
158     OTL_CHECK(4);
159 
160     tags = OTL_NEXT_USHORT( p );
161     if ( tags )
162       otl_base_tag_list_validate   ( table + tags );
163 
164     otl_base_script_list_validate( table + OTL_NEXT_USHORT( p ) );
165   }
166 
167 
168   OTL_LOCALDEF( void )
otl_base_validate(OTL_Bytes table,OTL_Validator valid)169   otl_base_validate( OTL_Bytes      table,
170                      OTL_Validator  valid )
171   {
172     OTL_Bytes p = table;
173 
174     OTL_CHECK(6);
175 
176     if ( OTL_NEXT_ULONG( p ) != 0x10000UL )
177       OTL_INVALID_DATA;
178 
179     otl_axis_table_validate( table + OTL_NEXT_USHORT( p ) );
180     otl_axis_table_validate( table + OTL_NEXT_USHORT( p ) );
181   }