shithub: freetype+ttf2subf

Download patch

ref: 1dacbd893d3c2f027b5c79f504d8899a68112c0c
parent: ca980b4cf11405469a5b5919dc40e73c4961c7c7
author: Alexei Podtelezhnikov <[email protected]>
date: Thu Aug 30 19:28:30 EDT 2018

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.

git/fs: mount .git/fs: mount/attach disallowed
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,18 @@
 2018-08-30  Alexei Podtelezhnikov  <[email protected]>
 
+	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  <[email protected]>
+
 	* src/base/ftobjs.c (ft_glyphslot_preset_bitmap): Correct mono.
 
 2018-08-30  Armin Hasitzka  <[email protected]>
--- a/include/freetype/internal/ftobjs.h
+++ b/include/freetype/internal/ftobjs.h
@@ -701,8 +701,9 @@
   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 );
--- 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;
   }
 
 
--- 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;
     }
--- 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;
     }