/* * ZDI-CAN-30558: BitmapScaleBitmaps bytestoalloc integer overflow * * The font has 1105 small glyphs (1x2 pixels) stored at pixel=1. When * loaded at a larger pixel size, the bitmap scaler inflates each glyph. * With the old 'unsigned int' bytestoalloc, the accumulated size could * wrap past 2^32, causing calloc to allocate a tiny buffer while * ScaleBitmap writes the full (unwrapped) amount. * * With the fix in bitscale.c, bytestoalloc is size_t (no 32-bit wrap * on 64-bit platforms) and an explicit overflow check prevents wrap on * 32-bit platforms. * * Test font: test/data/scale/evil-scale.pcf * Generated by: test/gen_evil_pcf_bitmapscale.py */ /* * Copyright (c) 2026, Red Hat, Inc. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice (including the next * paragraph) shall be included in all copies or substantial portions of the * Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * DEALINGS IN THE SOFTWARE. */ #include "pcf-test-common.h" #include #include int main(int argc, char **argv) { xfont2_fpe_funcs_rec const **fpe_functions; int fpe_function_count; const char *builddir; char fontdir[512]; builddir = getenv("builddir"); if (!builddir) builddir = "."; fpe_functions = pcf_test_init(&fpe_function_count); snprintf(fontdir, sizeof(fontdir), "%s/test/data/scale", builddir); /* Request pixel=16384 to inflate each glyph to ~62 MiB, causing the * total to exceed 256 MiB and trigger the size limit check. * Without the fix, the unsigned int accumulator wraps to ~1.5 MiB, * calloc succeeds, and ScaleBitmap overflows the buffer. */ return pcf_test_open_font(fpe_functions, "ZDI-CAN-30558-scale", fontdir, "-evil-scale-medium-r-normal--16384-0-75-75-c-0-iso10646-1"); }