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