Commit 1dacbd893d3c2f027b5c79f504d8899a68112c0c

Alexei Podtelezhnikov 2018-08-30T23:28:30

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.

diff --git a/ChangeLog b/ChangeLog
index 0b945f8..14655a3 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,18 @@
 2018-08-30  Alexei Podtelezhnikov  <apodtele@gmail.com>
 
+	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  <apodtele@gmail.com>
+
 	* src/base/ftobjs.c (ft_glyphslot_preset_bitmap): Correct mono.
 
 2018-08-30  Armin Hasitzka  <prince.cherusker@gmail.com>
diff --git a/include/freetype/internal/ftobjs.h b/include/freetype/internal/ftobjs.h
index eaae53e..4e7d57c 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 f245430..ddcf090 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 e8ea9cb..43e9e65 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 d8e3351..41aca31 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;
     }