1 /*
2 * Copyright (C) 2023 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 #include <ft2build.h>
18 #include FT_FREETYPE_H
19 #include "../includes/common.h"
20 #include <freetype/internal/ftdebug.h>
21
22 FT_Face face = nullptr;
23 FT_Library library = nullptr;
24
exitHandler(void)25 void exitHandler(void) {
26 if (face) {
27 FT_Done_Face(face);
28 }
29 if (library) {
30 FT_Done_FreeType(library);
31 }
32 }
33
main(int argc,char ** argv)34 int main(int argc, char **argv) {
35 FAIL_CHECK(argc == 3);
36 atexit(exitHandler);
37 // Initialize FreeType library
38 FT_Error error = FT_Init_FreeType(&library);
39 FAIL_CHECK(!error);
40
41 // Load the font file
42 const int face_index = -1;
43 error = FT_New_Face(library, argv[2], face_index, &face);
44 FAIL_CHECK(!error);
45 if (strcmp(argv[1], "CVE-2022-27406")) {
46 return (face->face_index == face_index) ? EXIT_VULNERABLE : EXIT_SUCCESS;
47 }
48 face->size = nullptr;
49 error = FT_Set_Char_Size(face, 0 /* char_width */, 0 /* char_height */,
50 0 /* horz_resolution */, 0 /* vert_resolution */);
51 FAIL_CHECK((error == FT_THROW(Invalid_Size_Handle)));
52 return EXIT_SUCCESS;
53 }
54