File: HowToTest.md

package info (click to toggle)
opentype-sanitizer 8.2.1%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 1,164 kB
  • sloc: cpp: 17,010; makefile: 3
file content (276 lines) | stat: -rw-r--r-- 7,157 bytes parent folder | download | duplicates (9)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
Test suite
==========

## Prerequisites

On Ubuntu, install as many as possible TrueType and OpenType fonts:

    $ sudo apt-get install ttf-.*[^0]$

On Mac OS X, fonts installed on `/Library/Fonts/` and `/System/Library/Fonts/`
will be used.

## Running the tests

Simply run:

    $ make check

Which will run tests to verify that:

1. OTS does not reject these unmalicious fonts.
2. OTS can reject these malicious fonts.
3. The transcoded fonts OTS generates can be loaded by a system font renderer
   (FreeType, Core Text or GDI) and do not crash it.
4. Fuzzed fonts do not hang or crash OTS.

Command line tools
==================

We have some command line tools for tests.

## `ots-sanitize` - font validator/transcoder

### Description:
`ots-sanitize` is a program which validates and/or transcodes a font file using
the OTS library:

    transcoded_font = ValidateAndTranscode(original_font);
    if (validation_error)
      PrintErrorAndExit;
    OutputToStdout(transcoded_font);

### Usage:

    $ ./ots-sanitize ttf_or_otf_file [transcoded_file]

### Example:

    $ ./ots-sanitize sample.otf transcoded_sample.otf
    $ ./ots-sanitize malformed.ttf
    WARNING: bad range shift
    ERROR at src/ots.cc:670 (ProcessGeneric)
    Failed to sanitize file!

## `ots-idempotent` — font transcoder

### Description:
`ots-idempotent` is a program which validates and transcodes a font file using OTS.
This tool transcodes the original font twice and then verifies that the two
transcoded fonts are identical:

    t1 = ValidateAndTranscode(original_font);
    if (validation_error)
      PrintErrorAndExit;
    t2 = ValidateAndTranscode(t1);
    if (validation_error)
      PrintErrorAndExit;
    if (t1 != t2)
      PrintErrorAndExit;

This tool is basically for OTS developers.

### Usage:

    $ ./ots-idempotent ttf_or_otf_file

### Example:

    $ ./ots-idempotent sample.otf
    $ ./ots-idempotent malformed.ttf
    WARNING: bad range shift
    ERROR at src/ots.cc:670 (ProcessGeneric)
    Failed to sanitize file!

## `ots-validator-checker` — font validation checker

### Description:
`ots-validator-checker` is a program which is intended to validate malformed fonts.
If the program detects that the font is invalid, it prints “OK” and returns
with 0 (success). If it couldn’t detect any errors, the program then opens the
transcoded font and renders some characters using FreeType:

    transcoded_font = ValidateAndTranscode(malicious_font);
    if (validation_error)
      Print("OK");
    OpenAndRenderSomeCharacters(transcoded_font);  # may cause SIGSEGV
    Print("OK");

If SEGV doesn't raise inside FreeType library, the program prints “OK” and
returns with 0 as well. You should run this tool under the catchsegv or
valgrind command so that you can easily verify that all transformed fonts don't
crash the library (see the example below).

### Usage:

    $ catchsegv ./validator_checker malicous_ttf_or_otf_file

### Example:

    $ for f in malformed/*.ttf ; do catchsegv ./ots-validator-checker "$f" ; done
    OK: the malicious font was filtered: malformed/1.ttf
    OK: the malicious font was filtered: malformed/2.ttf
    OK: FreeType2 didn't crash: malformed/3.ttf
    OK: the malicious font was filtered: malformed/4.ttf

## `ots-perf` — performance checker

### Description:
`ots-perf` is a program which validates and transcodes a font file N times using
OTS, then prints the elapsed time:

    for (N times)
      ValidateAndTranscode(original_font);
    Print(elapsed_time_in_us / N);

### Usage:

    $ ./ots-perf ttf_or_otf_file

### Example:

    $ ./ots-perf sample.ttf
    903 [us] sample.ttf (139332 bytes, 154 [byte/us])
    $ ./ots-perf sample-bold.otf
    291 [us] sample-bold.otf (150652 bytes, 517 [byte/us])

## `ots-side-by-side` — font quality checker

### Description:
`ots-side-by-side` is a program which renders some characters (ASCII, Latin-1, CJK)
using both original font and transcoded font and checks that the two rendering
results are exactly equal.

The following Unicode characters are used during the test:

    0x0020 - 0x007E  // Basic Latin
    0x00A1 - 0x017F  // Latin-1
    0x1100 - 0x11FF  // Hangul
    0x3040 - 0x309F  // Japanese HIRAGANA letters
    0x3130 - 0x318F  // Hangul
    0x4E00 - 0x4F00  // CJK Kanji/Hanja
    0xAC00 - 0xAD00  // Hangul

This tool uses FreeType library.

Note: This tool doesn't check kerning (GPOS/kern) nor font substitution
(GSUB). These should be tested in Layout tests if necessary.

### Usage:

    $ ./ots-side-by-side ttf_or_otf_file

### Example:

    $ ./ots-side-by-side linux/kochi-gothic.ttf  # no problem
    $ ./ots-side-by-side free/kredit1.ttf        # this is known issue of OTS.
    bitmap metrics doesn't match! (14, 57), (37, 45)
    EXPECTED:

      +#######*.
     +##########+
    .###+.#.   .#.
    *#*   #     #*
    ##.   #     ##
    ##    #     ##
    ##    #     ##
    ##    #.    ##
    ##.   #.   .##
    ##.   #.   .##
    *#+   *+   +#*
    *#+   *+   +#*
    *#+   *+   +#*
    *#+   *+   +#*
    *#+   *+   *#*
    *#+   ++   *#+
    +#*   +*   *#+
    +#*   +*   *#+
    +#*   +*   *#+
    +#*   +*   ##.
    +#*   +*   ##.
    .##   .#   ##
    .##   .#   ##
    .##   .#   ##
     ##    #   ##
     ##    #   ##
     ##    #  .##
     ##    #  .##
     ##   .#+ +#*
     ##  +######*
     ##.+#######*
     *##########*
     +##########+
      #########*
      .########
        +####+






      .*######*
     +##*.*#####
    .##+.#+    +#
    *#* ##      #+
    ##*###      ##
    ######      ##
    ##+.##+    +##
    ##  ##########
    ##  +#########
    ##   +########
    *#. .########*
    .#* #########.
     +##########+
      +*######*

    ACTUAL:

      .*##*+
     +##+.##*.
    .#* .##.+#*
    *#  ###   *#+
    #*######+  .*#+
    #########*.  +#*.
    ###########*   +#*
    *############+   *#+
    +##############.  .##.
     *##############*   +#*
      +###############+   *#+
        *###############+  .*#+
         .###############*.  +#*.
           +###############*   +#*
             *###############+   *#+
              .*###############+  .*#+
                +###############*.  +#*
                  +###############*   **
                    *###############+  #+
                     .###############* ##
                       +############+  ##
                         +########*   .##
                          .######.   +###
                         +#####+   .*#..#
                       +#####*    *###..#
                      *#####.   +#######*
                    +#####+   .*########.
                  +#####*    +#########*
                 *#####.   +##########+
               +#####+    *#########*.
             .#####*    +##########+
            *#####.   +##########*
          +#####+    *#########*.
        .#####*    +##########+
       *#####+   +##########*
     .#*++#+    *#########*.
    .#+  ##   +##########+
    ****###+.##########*
    ##################.
    ###+  *#########+
    ##   +########*
    *#+ *########.
     ##.#######+
     +#######*
       *###*.


    Glyph mismatch! (file: free/kredit1.ttf, U+0021, 100pt)!