[base, smooth] Fortify direct rendering.

This is a better fix for #1384, which is rather about signed overflow.

* include/freetype/ftimage.h (FT_Span): Use unsigned position.
* src/smooth/ftgrays.c (gray_sweep_direct): Sync with FT_Span.
* src/smooth/ftsmooth.c (ft_smooth_render): Remove redundant shift.
* src/base/ftobjs.c (ft_glyphslot_preset_bitmap): Readjust limits.
This commit is contained in:
Alexei Podtelezhnikov
2026-01-17 22:55:16 -05:00
parent dad4640660
commit ef04e4eb20
4 changed files with 8 additions and 20 deletions

View File

@@ -875,7 +875,7 @@ FT_BEGIN_HEADER
*/
typedef struct FT_Span_
{
short x;
unsigned short x;
unsigned short len;
unsigned char coverage;

View File

@@ -526,27 +526,21 @@
/* Flag the bounding box size unsuitable for rendering. */
/* FT_Renderer modules should check the return value. */
/* The limit is based on the ppem value when available. */
/* The limit is based on the ppem value when available. */
{
FT_Face face = slot->face;
FT_Pos xlim = 0x7FFF;
FT_Pos ylim = 0x7FFF;
FT_Pos xlim = 0x8000;
FT_Pos ylim = 0x8000;
#ifdef FT_CONFIG_OPTION_SUBPIXEL_RENDERING
/* should fit 16-bit FT_Span after 3x implosion */
if ( mode == FT_RENDER_MODE_LCD )
xlim = 0x2AAA;
#endif
if ( face )
{
xlim = FT_MIN( xlim, 10 * face->size->metrics.x_ppem );
ylim = FT_MIN( ylim, 10 * face->size->metrics.y_ppem );
}
if ( pbox.xMin < -xlim || pbox.xMax > xlim ||
pbox.yMin < -ylim || pbox.yMax > ylim )
if ( pbox.xMin < -xlim || pbox.xMax >= xlim ||
pbox.yMin < -ylim || pbox.yMax >= ylim )
{
FT_TRACE3(( "ft_glyphslot_preset_bitmap: [%ld %ld %ld %ld]\n",
pbox.xMin, pbox.yMin, pbox.xMax, pbox.yMax ));

View File

@@ -1804,7 +1804,7 @@ typedef ptrdiff_t FT_PtrDist;
FT_FILL_RULE( coverage, cover, fill );
span[n].coverage = (unsigned char)coverage;
span[n].x = (short)x;
span[n].x = (unsigned short)x;
span[n].len = (unsigned short)( cell->x - x );
if ( ++n == FT_MAX_GRAY_SPANS )
@@ -1823,7 +1823,7 @@ typedef ptrdiff_t FT_PtrDist;
FT_FILL_RULE( coverage, area, fill );
span[n].coverage = (unsigned char)coverage;
span[n].x = (short)cell->x;
span[n].x = (unsigned short)cell->x;
span[n].len = 1;
if ( ++n == FT_MAX_GRAY_SPANS )

View File

@@ -494,12 +494,6 @@
else
y_shift += 64 * (FT_Int)bitmap->rows;
if ( origin )
{
x_shift += origin->x;
y_shift += origin->y;
}
/* translate outline to render it into the bitmap */
if ( x_shift || y_shift )
FT_Outline_Translate( outline, x_shift, y_shift );