1 /****************************************************************************
5 * FreeType validation support (specification).
7 * Copyright (C) 2004-2020 by
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.
23 #include FT_CONFIG_STANDARD_LIBRARY_H /* for ft_jmpbuf */
25 #include "compiler-macros.h"
30 /*************************************************************************/
31 /*************************************************************************/
32 /*************************************************************************/
35 /**** V A L I D A T I O N ****/
38 /*************************************************************************/
39 /*************************************************************************/
40 /*************************************************************************/
42 /* handle to a validation object */
43 typedef struct FT_ValidatorRec_ volatile* FT_Validator;
46 /**************************************************************************
48 * There are three distinct validation levels defined here:
50 * FT_VALIDATE_DEFAULT ::
51 * A table that passes this validation level can be used reliably by
52 * FreeType. It generally means that all offsets have been checked to
53 * prevent out-of-bound reads, that array counts are correct, etc.
55 * FT_VALIDATE_TIGHT ::
56 * A table that passes this validation level can be used reliably and
57 * doesn't contain invalid data. For example, a charmap table that
58 * returns invalid glyph indices will not pass, even though it can be
59 * used with FreeType in default mode (the library will simply return an
60 * error later when trying to load the glyph).
62 * It also checks that fields which must be a multiple of 2, 4, or 8,
63 * don't have incorrect values, etc.
65 * FT_VALIDATE_PARANOID ::
66 * Only for font debugging. Checks that a table follows the
67 * specification by 100%. Very few fonts will be able to pass this level
68 * anyway but it can be useful for certain tools like font
71 typedef enum FT_ValidationLevel_
73 FT_VALIDATE_DEFAULT = 0,
80 #if defined( _MSC_VER ) /* Visual C++ (and Intel C++) */
81 /* We disable the warning `structure was padded due to */
82 /* __declspec(align())' in order to compile cleanly with */
83 /* the maximum level of warnings. */
84 #pragma warning( push )
85 #pragma warning( disable : 4324 )
88 /* validator structure */
89 typedef struct FT_ValidatorRec_
91 ft_jmp_buf jump_buffer; /* used for exception handling */
93 const FT_Byte* base; /* address of table in memory */
94 const FT_Byte* limit; /* `base' + sizeof(table) in memory */
95 FT_ValidationLevel level; /* validation level */
96 FT_Error error; /* error returned. 0 means success */
100 #if defined( _MSC_VER )
101 #pragma warning( pop )
104 #define FT_VALIDATOR( x ) ( (FT_Validator)( x ) )
108 ft_validator_init( FT_Validator valid,
110 const FT_Byte* limit,
111 FT_ValidationLevel level );
113 /* Do not use this. It's broken and will cause your validator to crash */
114 /* if you run it on an invalid font. */
116 ft_validator_run( FT_Validator valid );
118 /* Sets the error field in a validator, then calls `longjmp' to return */
119 /* to high-level caller. Using `setjmp/longjmp' avoids many stupid */
120 /* error checks within the validation routines. */
123 ft_validator_error( FT_Validator valid,
127 /* Calls ft_validate_error. Assumes that the `valid' local variable */
128 /* holds a pointer to the current validator object. */
130 #define FT_INVALID( _error ) FT_INVALID_( _error )
131 #define FT_INVALID_( _error ) \
132 ft_validator_error( valid, FT_THROW( _error ) )
134 /* called when a broken table is detected */
135 #define FT_INVALID_TOO_SHORT \
136 FT_INVALID( Invalid_Table )
138 /* called when an invalid offset is detected */
139 #define FT_INVALID_OFFSET \
140 FT_INVALID( Invalid_Offset )
142 /* called when an invalid format/value is detected */
143 #define FT_INVALID_FORMAT \
144 FT_INVALID( Invalid_Table )
146 /* called when an invalid glyph index is detected */
147 #define FT_INVALID_GLYPH_ID \
148 FT_INVALID( Invalid_Glyph_Index )
150 /* called when an invalid field value is detected */
151 #define FT_INVALID_DATA \
152 FT_INVALID( Invalid_Table )
157 #endif /* FTVALID_H_ */