[paint] Clamp hb_color_lerp() channels to [0,255] (#6305)

Sweep-gradient color-stop angles come from the font, so the
interpolation fraction t can fall outside [0,1] (or be NaN).  The
interpolated channel was then cast float -> unsigned directly; a
negative value (e.g. -387.671) is UB (UBSan float-cast-overflow) and
yields meaningless colors on release builds.

Clamp the interpolated channel to [0,255], mapping NaN to 0, before
the cast.  In-range behavior is unchanged.  Add the reported fuzzer
input as a seed.

Reported by iceray-Li.

Co-authored-by: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
Behdad EsfahbodandClaude Sonnet 5.5 authored and GitHub committed 2026-09-30 18:22:41 -06:00
1 parent b7fca823a0
commit e6d5454350
2 files changed
+6 -1

No files matched your search

+6 -1
View File
@@ -294,7 +294,12 @@ hb_color_lerp (hb_color_t c0, hb_color_t c1, float t)
auto lerp = [&] (unsigned shift) -> unsigned {
unsigned v0 = (c0 >> shift) & 0xFF;
unsigned v1 = (c1 >> shift) & 0xFF;
return (unsigned) (v0 + t * ((float) v1 - (float) v0) + 0.5f);
float v = v0 + t * ((float) v1 - (float) v0) + 0.5f;
/* t may be outside [0,1] (or NaN) for malformed gradients;
* keep the float-to-unsigned conversion defined. */
if (!(v > 0.f)) return 0;
if (v > 255.f) return 255;
return (unsigned) v;
};
return HB_COLOR (lerp (0), lerp (8), lerp (16), lerp (24));
}