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.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106
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;
}