[raster, smooth] Reinstate bitmap size limits. This again moves outline and bitmap size checks one level up. * src/base/ftoutln.c (FT_Outline_Render): Explicitly reject enormous outlines. * src/raster/ftrend1.c (ft_raster1_render): Reject enormous bitmaps and, therefore, outlines that require them. * src/smooth/ftsmooth.c (ft_smooth_render_generic): Ditto. * src/raster/ftraster.c (ft_black_render): Remove outline size checks. * src/smooth/ftgrays.c (gray_raster_render): Ditto. [STANDALONE]: Remove `FT_Outline_Get_CBox' copy.
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 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277
diff --git a/ChangeLog b/ChangeLog
index 6a4ca57..9c0b012 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,19 @@
+2018-08-09 Alexei Podtelezhnikov <apodtele@gmail.com>
+
+ [raster, smooth] Reinstate bitmap size limits.
+
+ This again moves outline and bitmap size checks one level up.
+
+ * src/base/ftoutln.c (FT_Outline_Render): Explicitly reject enormous
+ outlines.
+ * src/raster/ftrend1.c (ft_raster1_render): Reject enormous bitmaps
+ and, therefore, outlines that require them.
+ * src/smooth/ftsmooth.c (ft_smooth_render_generic): Ditto.
+
+ * src/raster/ftraster.c (ft_black_render): Remove outline size checks.
+ * src/smooth/ftgrays.c (gray_raster_render): Ditto.
+ [STANDALONE]: Remove `FT_Outline_Get_CBox' copy.
+
2018-08-08 Alexei Podtelezhnikov <apodtele@gmail.com>
[pcf] Revert massive unsigning.
diff --git a/src/base/ftoutln.c b/src/base/ftoutln.c
index 09a6a1f..611b4f6 100644
--- a/src/base/ftoutln.c
+++ b/src/base/ftoutln.c
@@ -619,6 +619,7 @@
FT_Error error;
FT_Renderer renderer;
FT_ListNode node;
+ FT_BBox cbox;
if ( !library )
@@ -630,6 +631,11 @@
if ( !params )
return FT_THROW( Invalid_Argument );
+ FT_Outline_Get_CBox( outline, &cbox );
+ if ( cbox.xMin < -0x1000000L || cbox.yMin < -0x1000000L ||
+ cbox.xMax > 0x1000000L || cbox.yMax > 0x1000000L )
+ return FT_THROW( Invalid_Outline );
+
renderer = library->cur_renderer;
node = library->renderers.head;
diff --git a/src/raster/ftraster.c b/src/raster/ftraster.c
index eece0f8..8a583ea 100644
--- a/src/raster/ftraster.c
+++ b/src/raster/ftraster.c
@@ -3251,7 +3251,6 @@
{
const FT_Outline* outline = (const FT_Outline*)params->source;
const FT_Bitmap* target_map = params->target;
- FT_BBox cbox;
black_TWorker worker[1];
@@ -3292,24 +3291,6 @@
if ( !target_map->buffer )
return FT_THROW( Invalid );
- FT_Outline_Get_CBox( outline, &cbox );
-
- /* reject too large outline coordinates */
- if ( cbox.xMin < -0x1000000L || cbox.xMax > 0x1000000L ||
- cbox.yMin < -0x1000000L || cbox.yMax > 0x1000000L )
- return FT_THROW( Invalid );
-
- /* truncate the bounding box to integer pixels */
- cbox.xMin = cbox.xMin >> 6;
- cbox.yMin = cbox.yMin >> 6;
- cbox.xMax = ( cbox.xMax + 63 ) >> 6;
- cbox.yMax = ( cbox.yMax + 63 ) >> 6;
-
- /* reject too large glyphs */
- if ( cbox.xMax - cbox.xMin > 0xFFFF ||
- cbox.yMax - cbox.yMin > 0xFFFF )
- return FT_THROW( Invalid );
-
ras.outline = *outline;
ras.target = *target_map;
diff --git a/src/raster/ftrend1.c b/src/raster/ftrend1.c
index 205cd9b..e8ea9cb 100644
--- a/src/raster/ftrend1.c
+++ b/src/raster/ftrend1.c
@@ -129,6 +129,14 @@
ft_glyphslot_preset_bitmap( slot, mode, origin );
+ if ( bitmap->width > 0x7FFF || bitmap->rows > 0x7FFF )
+ {
+ FT_ERROR(( "ft_raster1_render: glyph is too large: %u x %u\n",
+ bitmap->width, bitmap->rows ));
+ error = FT_THROW( Raster_Overflow );
+ goto Exit;
+ }
+
/* allocate new one */
if ( FT_ALLOC_MULT( bitmap->buffer, bitmap->rows, bitmap->pitch ) )
goto Exit;
diff --git a/src/smooth/ftgrays.c b/src/smooth/ftgrays.c
index b6598aa..8f2a600 100644
--- a/src/smooth/ftgrays.c
+++ b/src/smooth/ftgrays.c
@@ -1611,83 +1611,6 @@ typedef ptrdiff_t FT_PtrDist;
return FT_THROW( Invalid_Outline );
}
-
- /**************************************************************************
- *
- * @Function:
- * FT_Outline_Get_CBox
- *
- * @Description:
- * Return an outline's `control box'. The control box encloses all
- * the outline's points, including Bézier control points. Though it
- * coincides with the exact bounding box for most glyphs, it can be
- * slightly larger in some situations (like when rotating an outline
- * that contains Bézier outside arcs).
- *
- * Computing the control box is very fast, while getting the bounding
- * box can take much more time as it needs to walk over all segments
- * and arcs in the outline. To get the latter, you can use the
- * `ftbbox' component, which is dedicated to this single task.
- *
- * @Input:
- * outline ::
- * A pointer to the source outline descriptor.
- *
- * @Output:
- * acbox ::
- * The outline's control box.
- *
- * @Note:
- * See @FT_Glyph_Get_CBox for a discussion of tricky fonts.
- */
-
- static void
- FT_Outline_Get_CBox( const FT_Outline* outline,
- FT_BBox *acbox )
- {
- TPos xMin, yMin, xMax, yMax;
-
-
- if ( outline && acbox )
- {
- if ( outline->n_points == 0 )
- {
- xMin = 0;
- yMin = 0;
- xMax = 0;
- yMax = 0;
- }
- else
- {
- FT_Vector* vec = outline->points;
- FT_Vector* limit = vec + outline->n_points;
-
-
- xMin = xMax = vec->x;
- yMin = yMax = vec->y;
- vec++;
-
- for ( ; vec < limit; vec++ )
- {
- TPos x, y;
-
-
- x = vec->x;
- if ( x < xMin ) xMin = x;
- if ( x > xMax ) xMax = x;
-
- y = vec->y;
- if ( y < yMin ) yMin = y;
- if ( y > yMax ) yMax = y;
- }
- }
- acbox->xMin = xMin;
- acbox->xMax = xMax;
- acbox->yMin = yMin;
- acbox->yMax = yMax;
- }
- }
-
#endif /* STANDALONE_ */
@@ -1832,7 +1755,7 @@ typedef ptrdiff_t FT_PtrDist;
{
const FT_Outline* outline = (const FT_Outline*)params->source;
const FT_Bitmap* target_map = params->target;
- FT_BBox cbox, clip;
+ FT_BBox clip;
#ifndef FT_STATIC_RASTER
gray_TWorker worker[1];
@@ -1895,26 +1818,11 @@ typedef ptrdiff_t FT_PtrDist;
ras.render_span_data = NULL;
}
- FT_Outline_Get_CBox( outline, &cbox );
-
- /* reject too large outline coordinates */
- if ( cbox.xMin < -0x1000000L || cbox.xMax > 0x1000000L ||
- cbox.yMin < -0x1000000L || cbox.yMax > 0x1000000L )
- return FT_THROW( Invalid_Outline );
-
- /* truncate the bounding box to integer pixels */
- cbox.xMin = cbox.xMin >> 6;
- cbox.yMin = cbox.yMin >> 6;
- cbox.xMax = ( cbox.xMax + 63 ) >> 6;
- cbox.yMax = ( cbox.yMax + 63 ) >> 6;
-
- /* reject too large glyphs */
- if ( cbox.xMax - cbox.xMin > 0xFFFF ||
- cbox.yMax - cbox.yMin > 0xFFFF )
- return FT_THROW( Invalid_Outline );
-
/* compute clipping box */
- if ( !( params->flags & FT_RASTER_FLAG_DIRECT ) )
+ if ( params->flags & FT_RASTER_FLAG_DIRECT &&
+ params->flags & FT_RASTER_FLAG_CLIP )
+ clip = params->clip_box;
+ else
{
/* compute clip box from target pixmap */
clip.xMin = 0;
@@ -1922,21 +1830,12 @@ typedef ptrdiff_t FT_PtrDist;
clip.xMax = (FT_Pos)target_map->width;
clip.yMax = (FT_Pos)target_map->rows;
}
- else if ( params->flags & FT_RASTER_FLAG_CLIP )
- clip = params->clip_box;
- else
- {
- clip.xMin = -32768L;
- clip.yMin = -32768L;
- clip.xMax = 32767L;
- clip.yMax = 32767L;
- }
/* clip to target bitmap, exit if nothing to do */
- ras.min_ex = FT_MAX( cbox.xMin, clip.xMin );
- ras.min_ey = FT_MAX( cbox.yMin, clip.yMin );
- ras.max_ex = FT_MIN( cbox.xMax, clip.xMax );
- ras.max_ey = FT_MIN( cbox.yMax, clip.yMax );
+ ras.min_ex = clip.xMin;
+ ras.min_ey = clip.yMin;
+ ras.max_ex = clip.xMax;
+ ras.max_ey = clip.yMax;
if ( ras.max_ex <= ras.min_ex || ras.max_ey <= ras.min_ey )
return 0;
diff --git a/src/smooth/ftsmooth.c b/src/smooth/ftsmooth.c
index 1007f39..c6b7e21 100644
--- a/src/smooth/ftsmooth.c
+++ b/src/smooth/ftsmooth.c
@@ -147,6 +147,14 @@
ft_glyphslot_preset_bitmap( slot, mode, origin );
+ if ( bitmap->width > 0x7FFF || bitmap->rows > 0x7FFF )
+ {
+ 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;
+ }
+
/* allocate new one */
if ( FT_ALLOC_MULT( bitmap->buffer, bitmap->rows, bitmap->pitch ) )
goto Exit;