freetype-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[freetype2-demos] master 794730a 1/2: [ftgrid] Fix memory-related proble


From: Werner Lemberg
Subject: [freetype2-demos] master 794730a 1/2: [ftgrid] Fix memory-related problems.
Date: Fri, 29 Jul 2022 18:34:35 -0400 (EDT)

branch: master
commit 794730a046e33deb9f77660bc424d84862a6270d
Author: Werner Lemberg <wl@gnu.org>
Commit: Werner Lemberg <wl@gnu.org>

    [ftgrid] Fix memory-related problems.
    
    Reported by Marc Schönefeld <marc.schoenefeld@gmx.org>.
    
    * src/ftgrid.c (bitmap_scale): Limit bitmap size.
    (grid_status_draw_outline): Handle errors in `FT_Get_Glyph`.
---
 src/ftgrid.c | 21 +++++++++++++++------
 1 file changed, 15 insertions(+), 6 deletions(-)

diff --git a/src/ftgrid.c b/src/ftgrid.c
index e63f15d..61b2769 100644
--- a/src/ftgrid.c
+++ b/src/ftgrid.c
@@ -408,8 +408,12 @@
                            : -bit->pitch;
     width = bit->width;
 
-    line = (unsigned char*)malloc( (size_t)( pitch * bit->rows *
-                                             scale * scale ) );
+    /* limit bitmap size */
+    if ( pitch * scale <= 0xFFFF && bit->rows * scale <= 0xFFFF )
+      line = (unsigned char*)malloc( (size_t)( pitch * bit->rows *
+                                               scale * scale ) );
+    else
+      line = NULL;
 
     bit->buffer = line;  /* the bitmap now owns this buffer */
 
@@ -585,10 +589,12 @@
       grBitmap  bitg;
 
 
-      FT_Get_Glyph( slot, &glyph );
-      error  = FTDemo_Glyph_To_Bitmap( handle, glyph, &bitg, &left, &top,
-                                       &x_advance, &y_advance, &glyf);
+      err = FT_Get_Glyph( slot, &glyph );
+      if ( err )
+        return;
 
+      error = FTDemo_Glyph_To_Bitmap( handle, glyph, &bitg, &left, &top,
+                                      &x_advance, &y_advance, &glyf);
       if ( !error )
       {
         bitmap_scale( st, &bitg, scale );
@@ -633,7 +639,10 @@
       /* stroke then draw it */
       if ( st->work & DO_OUTLINE )
       {
-        FT_Get_Glyph( slot, &glyph );
+        err = FT_Get_Glyph( slot, &glyph );
+        if ( err )
+          return;
+
         FT_Glyph_Stroke( &glyph, st->stroker, 1 );
 
         error = FTDemo_Sketch_Glyph_Color( handle, display, glyph,



reply via email to

[Prev in Thread] Current Thread [Next in Thread]