1 /***************************************************************************/
5 /* TrueTypeGX/AAT mort table validation */
6 /* body for type2 (Ligature Substitution) subtable. */
8 /* Copyright 2005-2016 by */
9 /* suzuki toshiya, Masatake YAMATO, Red Hat K.K., */
10 /* David Turner, Robert Wilhelm, and Werner Lemberg. */
12 /* This file is part of the FreeType project, and may only be used, */
13 /* modified, and distributed under the terms of the FreeType project */
14 /* license, LICENSE.TXT. By continuing to use, modify, or distribute */
15 /* this file you indicate that you have read the license and */
16 /* understand and accept it fully. */
18 /***************************************************************************/
20 /***************************************************************************/
22 /* gxvalid is derived from both gxlayout module and otvalid module. */
23 /* Development of gxlayout is supported by the Information-technology */
24 /* Promotion Agency(IPA), Japan. */
26 /***************************************************************************/
32 /*************************************************************************/
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. */
39 #define FT_COMPONENT trace_gxvmort
42 typedef struct GXV_mort_subtable_type2_StateOptRec_
44 FT_UShort ligActionTable
;
45 FT_UShort componentTable
;
46 FT_UShort ligatureTable
;
47 FT_UShort ligActionTable_length
;
48 FT_UShort componentTable_length
;
49 FT_UShort ligatureTable_length
;
51 } GXV_mort_subtable_type2_StateOptRec
,
52 *GXV_mort_subtable_type2_StateOptRecData
;
54 #define GXV_MORT_SUBTABLE_TYPE2_HEADER_SIZE \
55 ( GXV_STATETABLE_HEADER_SIZE + 2 + 2 + 2 )
59 gxv_mort_subtable_type2_opttable_load( FT_Bytes table
,
61 GXV_Validator gxvalid
)
64 GXV_mort_subtable_type2_StateOptRecData optdata
=
65 (GXV_mort_subtable_type2_StateOptRecData
)gxvalid
->statetable
.optdata
;
68 GXV_LIMIT_CHECK( 2 + 2 + 2 );
69 optdata
->ligActionTable
= FT_NEXT_USHORT( p
);
70 optdata
->componentTable
= FT_NEXT_USHORT( p
);
71 optdata
->ligatureTable
= FT_NEXT_USHORT( p
);
73 GXV_TRACE(( "offset to ligActionTable=0x%04x\n",
74 optdata
->ligActionTable
));
75 GXV_TRACE(( "offset to componentTable=0x%04x\n",
76 optdata
->componentTable
));
77 GXV_TRACE(( "offset to ligatureTable=0x%04x\n",
78 optdata
->ligatureTable
));
83 gxv_mort_subtable_type2_subtable_setup( FT_UShort table_size
,
87 FT_UShort
*classTable_length_p
,
88 FT_UShort
*stateArray_length_p
,
89 FT_UShort
*entryTable_length_p
,
90 GXV_Validator gxvalid
)
96 GXV_mort_subtable_type2_StateOptRecData optdata
=
97 (GXV_mort_subtable_type2_StateOptRecData
)gxvalid
->statetable
.optdata
;
100 GXV_NAME_ENTER( "subtable boundaries setup" );
105 o
[3] = optdata
->ligActionTable
;
106 o
[4] = optdata
->componentTable
;
107 o
[5] = optdata
->ligatureTable
;
108 l
[0] = classTable_length_p
;
109 l
[1] = stateArray_length_p
;
110 l
[2] = entryTable_length_p
;
111 l
[3] = &(optdata
->ligActionTable_length
);
112 l
[4] = &(optdata
->componentTable_length
);
113 l
[5] = &(optdata
->ligatureTable_length
);
115 gxv_set_length_by_ushort_offset( o
, l
, buff
, 6, table_size
, gxvalid
);
117 GXV_TRACE(( "classTable: offset=0x%04x length=0x%04x\n",
118 classTable
, *classTable_length_p
));
119 GXV_TRACE(( "stateArray: offset=0x%04x length=0x%04x\n",
120 stateArray
, *stateArray_length_p
));
121 GXV_TRACE(( "entryTable: offset=0x%04x length=0x%04x\n",
122 entryTable
, *entryTable_length_p
));
123 GXV_TRACE(( "ligActionTable: offset=0x%04x length=0x%04x\n",
124 optdata
->ligActionTable
,
125 optdata
->ligActionTable_length
));
126 GXV_TRACE(( "componentTable: offset=0x%04x length=0x%04x\n",
127 optdata
->componentTable
,
128 optdata
->componentTable_length
));
129 GXV_TRACE(( "ligatureTable: offset=0x%04x length=0x%04x\n",
130 optdata
->ligatureTable
,
131 optdata
->ligatureTable_length
));
138 gxv_mort_subtable_type2_ligActionOffset_validate(
140 FT_UShort ligActionOffset
,
141 GXV_Validator gxvalid
)
143 /* access ligActionTable */
144 GXV_mort_subtable_type2_StateOptRecData optdata
=
145 (GXV_mort_subtable_type2_StateOptRecData
)gxvalid
->statetable
.optdata
;
147 FT_Bytes lat_base
= table
+ optdata
->ligActionTable
;
148 FT_Bytes p
= table
+ ligActionOffset
;
149 FT_Bytes lat_limit
= lat_base
+ optdata
->ligActionTable
;
152 GXV_32BIT_ALIGNMENT_VALIDATE( ligActionOffset
);
155 GXV_TRACE(( "too short offset 0x%04x: p < lat_base (%d byte rewind)\n",
156 ligActionOffset
, lat_base
- p
));
158 /* FontValidator, ftxvalidator, ftxdumperfuser warn but continue */
159 GXV_SET_ERR_IF_PARANOID( FT_INVALID_OFFSET
);
161 else if ( lat_limit
< p
)
163 GXV_TRACE(( "too large offset 0x%04x: lat_limit < p (%d byte overrun)\n",
164 ligActionOffset
, p
- lat_limit
));
166 /* FontValidator, ftxvalidator, ftxdumperfuser warn but continue */
167 GXV_SET_ERR_IF_PARANOID( FT_INVALID_OFFSET
);
171 /* validate entry in ligActionTable */
173 #ifdef GXV_LOAD_UNUSED_VARS
180 lig_action
= FT_NEXT_ULONG( p
);
181 #ifdef GXV_LOAD_UNUSED_VARS
182 last
= (FT_UShort
)( ( lig_action
>> 31 ) & 1 );
183 store
= (FT_UShort
)( ( lig_action
>> 30 ) & 1 );
186 /* Apple spec defines this offset as a word offset */
187 offset
= lig_action
& 0x3FFFFFFFUL
;
188 if ( offset
* 2 < optdata
->ligatureTable
)
190 GXV_TRACE(( "too short offset 0x%08x:"
191 " 2 x offset < ligatureTable (%d byte rewind)\n",
192 offset
, optdata
->ligatureTable
- offset
* 2 ));
194 GXV_SET_ERR_IF_PARANOID( FT_INVALID_OFFSET
);
195 } else if ( offset
* 2 >
196 optdata
->ligatureTable
+ optdata
->ligatureTable_length
)
198 GXV_TRACE(( "too long offset 0x%08x:"
199 " 2 x offset > ligatureTable + ligatureTable_length"
200 " (%d byte overrun)\n",
202 optdata
->ligatureTable
+ optdata
->ligatureTable_length
205 GXV_SET_ERR_IF_PARANOID( FT_INVALID_OFFSET
);
212 gxv_mort_subtable_type2_entry_validate(
215 GXV_StateTable_GlyphOffsetCPtr glyphOffset_p
,
218 GXV_Validator gxvalid
)
220 #ifdef GXV_LOAD_UNUSED_VARS
221 FT_UShort setComponent
;
222 FT_UShort dontAdvance
;
227 FT_UNUSED( glyphOffset_p
);
231 #ifdef GXV_LOAD_UNUSED_VARS
232 setComponent
= (FT_UShort
)( ( flags
>> 15 ) & 1 );
233 dontAdvance
= (FT_UShort
)( ( flags
>> 14 ) & 1 );
236 offset
= (FT_UShort
)( flags
& 0x3FFFU
);
239 gxv_mort_subtable_type2_ligActionOffset_validate( table
, offset
,
245 gxv_mort_subtable_type2_ligatureTable_validate( FT_Bytes table
,
246 GXV_Validator gxvalid
)
248 GXV_mort_subtable_type2_StateOptRecData optdata
=
249 (GXV_mort_subtable_type2_StateOptRecData
)gxvalid
->statetable
.optdata
;
251 FT_Bytes p
= table
+ optdata
->ligatureTable
;
252 FT_Bytes limit
= table
+ optdata
->ligatureTable
253 + optdata
->ligatureTable_length
;
256 GXV_NAME_ENTER( "mort chain subtable type2 - substitutionTable" );
257 if ( 0 != optdata
->ligatureTable
)
259 /* Apple does not give specification of ligatureTable format */
265 GXV_LIMIT_CHECK( 2 );
266 lig_gid
= FT_NEXT_USHORT( p
);
268 if ( gxvalid
->face
->num_glyphs
< lig_gid
)
269 GXV_SET_ERR_IF_PARANOID( FT_INVALID_GLYPH_ID
);
277 gxv_mort_subtable_type2_validate( FT_Bytes table
,
279 GXV_Validator gxvalid
)
283 GXV_mort_subtable_type2_StateOptRec lig_rec
;
286 GXV_NAME_ENTER( "mort chain subtable type2 (Ligature Substitution)" );
288 GXV_LIMIT_CHECK( GXV_MORT_SUBTABLE_TYPE2_HEADER_SIZE
);
290 gxvalid
->statetable
.optdata
=
292 gxvalid
->statetable
.optdata_load_func
=
293 gxv_mort_subtable_type2_opttable_load
;
294 gxvalid
->statetable
.subtable_setup_func
=
295 gxv_mort_subtable_type2_subtable_setup
;
296 gxvalid
->statetable
.entry_glyphoffset_fmt
=
297 GXV_GLYPHOFFSET_NONE
;
298 gxvalid
->statetable
.entry_validate_func
=
299 gxv_mort_subtable_type2_entry_validate
;
301 gxv_StateTable_validate( p
, limit
, gxvalid
);
303 p
+= gxvalid
->subtable_length
;
304 gxv_mort_subtable_type2_ligatureTable_validate( table
, gxvalid
);
306 gxvalid
->subtable_length
= (FT_ULong
)( p
- table
);