[raster] Clamp reflected gradient LUT coordinates

Malformed reflected gradients can produce very large finite
gradient parameters. The raster backend normalized reflect
mode by casting floorf(t) to int, which can overflow and
drive LUT lookups past the fixed-size stack buffer.

Fold reflected coordinates with fmodf(), clamp LUT inputs
defensively, and add the minimized oss-fuzz raster
testcase to the corpus.

Fixes: https://oss-fuzz.com/testcase-detail/6597066439852032
Tested: meson test -C build
Co-Authored-By: OpenAI Codex <codex@openai.com>
This commit is contained in:
Behdad EsfahbodandOpenAI Codex committed 2026-04-06 17:13:58 -06:00
1 parent 5ce0b12729
commit 03c262d1eb
2 files changed
+13 -8

No files matched your search

+13 -8
View File
@@ -954,6 +954,13 @@ normalize_color_line (hb_color_stop_t *stops,
*omax = mx;
}
static HB_ALWAYS_INLINE float
reflect_gradient_t (float t)
{
t = fmodf (fabsf (t), 2.f);
return t > 1.f ? 2.f - t : t;
}
/* Evaluate color at normalized position t, interpolating in premultiplied space. */
static uint32_t
evaluate_color_line (const hb_color_stop_t *stops, unsigned len, float t,
@@ -977,10 +984,7 @@ evaluate_color_line (const hb_color_stop_t *stops, unsigned len, float t,
}
else /* REFLECT */
{
if (t < 0) t = -t;
int period = (int) floorf (t);
float frac = t - (float) period;
t = (period & 1) ? 1.f - frac : frac;
t = reflect_gradient_t (t);
}
/* Find bounding stops */
@@ -1039,10 +1043,7 @@ normalize_gradient_t (float t, hb_paint_extend_t extend)
}
/* REFLECT */
if (t < 0.f) t = -t;
int period = (int) floorf (t);
float frac = t - (float) period;
return (period & 1) ? 1.f - frac : frac;
return reflect_gradient_t (t);
}
static void
@@ -1063,6 +1064,10 @@ lookup_gradient_lut (const uint32_t *lut,
hb_paint_extend_t extend)
{
float u = normalize_gradient_t (t, extend);
if (unlikely (!std::isfinite (u)))
u = 0.f;
else
u = hb_clamp (u, 0.f, 1.f);
unsigned idx = (unsigned) (u * (GRADIENT_LUT_SIZE - 1) + 0.5f);
return lut[idx];
}