mirror of
https://github.com/storytold/harfbuzz.git
synced 2026-11-24 08:21:32 +01:00
The curve accumulator grew without bound, reaching 2.9 GB on fuzzer-crafted inputs (VARC components expanded recursively, or cu2qu subdivisions on degenerate cubics, or a glyf with absurd contour counts). libFuzzer flags this as OOM. Add HB_GPU_DRAW_MAX_CURVES = 0x10000 (65536) -- far above any real glyph's needs -- and refuse to emit beyond it, flipping success=false so the encoder returns a valid empty/failure blob. Catches all upstream explosions (glyf / cu2qu / VARC / any future source) at the single choke point. Found by oss-fuzz/CIFuzz on hb-gpu-fuzzer. Assisted-by: Claude <noreply@anthropic.com>
142 lines
3.5 KiB
C++
142 lines
3.5 KiB
C++
/*
|
|
* Copyright © 2022 Behdad Esfahbod
|
|
*
|
|
* This is part of HarfBuzz, a text shaping library.
|
|
*
|
|
* Permission is hereby granted, without written agreement and without
|
|
* license or royalty fees, to use, copy, modify, and distribute this
|
|
* software and its documentation for any purpose, provided that the
|
|
* above copyright notice and the following two paragraphs appear in
|
|
* all copies of this software.
|
|
*
|
|
* IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR
|
|
* DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
|
|
* ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN
|
|
* IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
|
|
* DAMAGE.
|
|
*
|
|
* THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING,
|
|
* BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
|
* FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
|
|
* ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO
|
|
* PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
|
|
*/
|
|
|
|
#ifndef HB_LIMITS_HH
|
|
#define HB_LIMITS_HH
|
|
|
|
#include "hb.hh"
|
|
|
|
|
|
#ifndef HB_BUFFER_MAX_LEN_FACTOR
|
|
#define HB_BUFFER_MAX_LEN_FACTOR 256
|
|
#endif
|
|
#ifndef HB_BUFFER_MAX_LEN_MIN
|
|
#define HB_BUFFER_MAX_LEN_MIN 65536
|
|
#endif
|
|
#ifndef HB_BUFFER_MAX_LEN_DEFAULT
|
|
#define HB_BUFFER_MAX_LEN_DEFAULT 0x3FFFFFFF /* Shaping more than a billion chars? Let us know! */
|
|
#endif
|
|
|
|
#ifndef HB_BUFFER_MAX_OPS_FACTOR
|
|
#define HB_BUFFER_MAX_OPS_FACTOR 4096
|
|
#endif
|
|
#ifndef HB_BUFFER_MAX_OPS_MIN
|
|
#define HB_BUFFER_MAX_OPS_MIN 65536
|
|
#endif
|
|
#ifndef HB_BUFFER_MAX_OPS_DEFAULT
|
|
#define HB_BUFFER_MAX_OPS_DEFAULT 0x1FFFFFFF /* Shaping more than a billion operations? Let us know! */
|
|
#endif
|
|
|
|
|
|
#ifndef HB_MAX_NESTING_LEVEL
|
|
#define HB_MAX_NESTING_LEVEL 64
|
|
#endif
|
|
|
|
|
|
#ifndef HB_MAX_CONTEXT_LENGTH
|
|
#define HB_MAX_CONTEXT_LENGTH 64
|
|
#endif
|
|
|
|
#ifndef HB_CLOSURE_MAX_STAGES
|
|
/*
|
|
* The maximum number of times a lookup can be applied during shaping.
|
|
* Used to limit the number of iterations of the closure algorithm.
|
|
* This must be larger than the number of times add_gsub_pause() is
|
|
* called in a collect_features call of any shaper.
|
|
*/
|
|
#define HB_CLOSURE_MAX_STAGES 12
|
|
#endif
|
|
|
|
#ifndef HB_MAX_SCRIPTS
|
|
#define HB_MAX_SCRIPTS 500
|
|
#endif
|
|
|
|
#ifndef HB_MAX_LANGSYS
|
|
#define HB_MAX_LANGSYS 2000
|
|
#endif
|
|
|
|
#ifndef HB_MAX_LANGSYS_FEATURE_COUNT
|
|
#define HB_MAX_LANGSYS_FEATURE_COUNT 50000
|
|
#endif
|
|
|
|
#ifndef HB_MAX_FEATURE_INDICES
|
|
#define HB_MAX_FEATURE_INDICES 1500
|
|
#endif
|
|
|
|
#ifndef HB_MAX_LOOKUP_VISIT_COUNT
|
|
#define HB_MAX_LOOKUP_VISIT_COUNT 35000
|
|
#endif
|
|
|
|
#ifndef HB_MAX_GRAPH_EDGE_COUNT
|
|
#define HB_MAX_GRAPH_EDGE_COUNT 2048
|
|
#endif
|
|
|
|
#ifndef HB_VAR_COMPOSITE_MAX_AXES
|
|
#define HB_VAR_COMPOSITE_MAX_AXES 4096
|
|
#endif
|
|
|
|
#ifndef HB_GLYF_MAX_POINTS
|
|
#define HB_GLYF_MAX_POINTS 200000
|
|
#endif
|
|
|
|
#ifndef HB_CFF_MAX_OPS
|
|
#define HB_CFF_MAX_OPS 200000
|
|
#endif
|
|
|
|
#ifndef HB_MAX_COMPOSITE_OPERATIONS_PER_GLYPH
|
|
#define HB_MAX_COMPOSITE_OPERATIONS_PER_GLYPH 64
|
|
#endif
|
|
|
|
#ifndef HB_SVG_MAX_PATH_SEGMENTS
|
|
#define HB_SVG_MAX_PATH_SEGMENTS 262144
|
|
#endif
|
|
|
|
#ifndef HB_GPU_DRAW_MAX_CURVES
|
|
#define HB_GPU_DRAW_MAX_CURVES 65536
|
|
#endif
|
|
|
|
#ifndef HB_SVG_MAX_DOCUMENT_SIZE
|
|
#define HB_SVG_MAX_DOCUMENT_SIZE ((size_t) 16 << 20)
|
|
#endif
|
|
|
|
#ifndef HB_RASTER_MAX_BUFFER_SIZE
|
|
#define HB_RASTER_MAX_BUFFER_SIZE ((size_t) 1 << 30)
|
|
#endif
|
|
|
|
|
|
#ifndef HB_REPACKER_MAX_ITERATIONS
|
|
#define HB_REPACKER_MAX_ITERATIONS 500
|
|
#endif
|
|
|
|
#ifndef HB_REPACKER_MAX_VERTICES
|
|
#define HB_REPACKER_MAX_VERTICES 100000
|
|
#endif
|
|
|
|
#ifndef HB_REPACKER_MAX_SPACES
|
|
#define HB_REPACKER_MAX_SPACES 1024
|
|
#endif
|
|
|
|
|
|
#endif /* HB_LIMITS_HH */
|