From 1dacbd893d3c2f027b5c79f504d8899a68112c0c Mon Sep 17 00:00:00 2001 From: Alexei Podtelezhnikov Date: Thu, 30 Aug 2018 23:28:30 -0400 Subject: [PATCH] Consolidate bitmap presetting and size assessment. * include/freetype/internal/ftobjs.h (ft_glyphslot_preset_bitmap): Change return type. * src/base/ftobjs.c (ft_glyphslot_preset_bitmap): Return the bitmap size assessment. * src/raster/ftrend1.c (ft_raster1_render): Use it to refuse the rendering of enourmous or far-fetched outlines. * src/smooth/ftsmooth.c (ft_smooth_render_generic): Ditto. --- ChangeLog | 13 +++++++++++++ include/freetype/internal/ftobjs.h | 5 +++-- src/base/ftobjs.c | 13 ++++++++++++- src/raster/ftrend1.c | 6 +----- src/smooth/ftsmooth.c | 6 +----- 5 files changed, 30 insertions(+), 13 deletions(-) diff --git a/ChangeLog b/ChangeLog index 0b945f860..14655a329 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,16 @@ +2018-08-30 Alexei Podtelezhnikov + + Consolidate bitmap presetting and size assessment. + + * include/freetype/internal/ftobjs.h (ft_glyphslot_preset_bitmap): + Change return type. + * src/base/ftobjs.c (ft_glyphslot_preset_bitmap): Return the bitmap + size assessment. + + * src/raster/ftrend1.c (ft_raster1_render): Use it to refuse the + rendering of enourmous or far-fetched outlines. + * src/smooth/ftsmooth.c (ft_smooth_render_generic): Ditto. + 2018-08-30 Alexei Podtelezhnikov * src/base/ftobjs.c (ft_glyphslot_preset_bitmap): Correct mono. diff --git a/include/freetype/internal/ftobjs.h b/include/freetype/internal/ftobjs.h index eaae53eac..4e7d57c37 100644 --- a/include/freetype/internal/ftobjs.h +++ b/include/freetype/internal/ftobjs.h @@ -701,8 +701,9 @@ FT_BEGIN_HEADER ft_glyphslot_free_bitmap( FT_GlyphSlot slot ); - /* Preset bitmap metrics of an outline glyphslot prior to rendering. */ - FT_BASE( void ) + /* Preset bitmap metrics of an outline glyphslot prior to rendering */ + /* and check if the truncated bbox is too large for rendering. */ + FT_BASE( FT_Bool ) ft_glyphslot_preset_bitmap( FT_GlyphSlot slot, FT_Render_Mode mode, const FT_Vector* origin ); diff --git a/src/base/ftobjs.c b/src/base/ftobjs.c index f245430ec..ddcf09011 100644 --- a/src/base/ftobjs.c +++ b/src/base/ftobjs.c @@ -343,7 +343,8 @@ /* overflow-resistant presetting of bitmap position and dimensions */ - FT_BASE_DEF( void ) + /* also checks if the size is too large for rendering */ + FT_BASE_DEF( FT_Bool ) ft_glyphslot_preset_bitmap( FT_GlyphSlot slot, FT_Render_Mode mode, const FT_Vector* origin ) @@ -480,6 +481,16 @@ bitmap->width = (unsigned int)width; bitmap->rows = (unsigned int)height; bitmap->pitch = pitch; + + if ( pbox.xMin < -0x8000 || pbox.xMax > 0x7FFF || + pbox.yMin < -0x8000 || pbox.yMax > 0x7FFF ) + { + FT_TRACE3(( "ft_glyphslot_peset_bitmap: [%ld %ld %ld %ld]\n", + pbox.xMin, pbox.yMin, pbox.xMax, pbox.yMax )); + return 1; + } + + return 0; } diff --git a/src/raster/ftrend1.c b/src/raster/ftrend1.c index e8ea9cbe1..43e9e65c6 100644 --- a/src/raster/ftrend1.c +++ b/src/raster/ftrend1.c @@ -127,12 +127,8 @@ slot->internal->flags &= ~FT_GLYPH_OWN_BITMAP; } - ft_glyphslot_preset_bitmap( slot, mode, origin ); - - if ( bitmap->width > 0x7FFF || bitmap->rows > 0x7FFF ) + if ( ft_glyphslot_preset_bitmap( slot, mode, origin ) ) { - FT_ERROR(( "ft_raster1_render: glyph is too large: %u x %u\n", - bitmap->width, bitmap->rows )); error = FT_THROW( Raster_Overflow ); goto Exit; } diff --git a/src/smooth/ftsmooth.c b/src/smooth/ftsmooth.c index d8e335183..41aca31df 100644 --- a/src/smooth/ftsmooth.c +++ b/src/smooth/ftsmooth.c @@ -145,12 +145,8 @@ slot->internal->flags &= ~FT_GLYPH_OWN_BITMAP; } - ft_glyphslot_preset_bitmap( slot, mode, origin ); - - if ( bitmap->width > 0x7FFF || bitmap->rows > 0x7FFF ) + if ( ft_glyphslot_preset_bitmap( slot, mode, origin ) ) { - FT_ERROR(( "ft_smooth_render_generic: glyph is too large: %u x %u\n", - bitmap->width, bitmap->rows )); error = FT_THROW( Raster_Overflow ); goto Exit; }