Home | History | Annotate | Line # | Download | only in test
test-pcf-encoding.c revision 1.1.1.1
      1 /*
      2  * PCF encoding offset out-of-bounds access
      3  *
      4  * The font has 1 metric but an encoding entry that references index 100,
      5  * far past the metrics array.  Without the fix, this creates a wild
      6  * pointer that is later dereferenced.
      7  *
      8  * With the fix in pcfread.c, encoding offsets are validated against
      9  * nmetrics.
     10  *
     11  * Test font: test/data/encoding/evil-encoding.pcf
     12  * Generated by: test/gen_evil_pcf_encoding.py
     13  */
     14 
     15 /*
     16  * Copyright (c) 2026, Red Hat, Inc.
     17  *
     18  * Permission is hereby granted, free of charge, to any person obtaining a
     19  * copy of this software and associated documentation files (the "Software"),
     20  * to deal in the Software without restriction, including without limitation
     21  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
     22  * and/or sell copies of the Software, and to permit persons to whom the
     23  * Software is furnished to do so, subject to the following conditions:
     24  *
     25  * The above copyright notice and this permission notice (including the next
     26  * paragraph) shall be included in all copies or substantial portions of the
     27  * Software.
     28  *
     29  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
     30  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
     31  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
     32  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
     33  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
     34  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
     35  * DEALINGS IN THE SOFTWARE.
     36  */
     37 
     38 #include "pcf-test-common.h"
     39 #include <stdio.h>
     40 #include <stdlib.h>
     41 
     42 int
     43 main(int argc, char **argv)
     44 {
     45     xfont2_fpe_funcs_rec const **fpe_functions;
     46     int fpe_function_count;
     47     const char *builddir;
     48     char fontdir[512];
     49 
     50     builddir = getenv("builddir");
     51     if (!builddir)
     52         builddir = ".";
     53 
     54     fpe_functions = pcf_test_init(&fpe_function_count);
     55 
     56     snprintf(fontdir, sizeof(fontdir), "%s/test/data/encoding", builddir);
     57     return pcf_test_open_font(fpe_functions,
     58                               "pcf-encoding-oob",
     59                               fontdir,
     60                               "-evil-encoding-medium-r-normal--10-100-75-75-c-80-iso10646-1");
     61 }
     62