[bdf, cff] Integer overflows. Reported as https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=2244 https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=2261 * src/bdf/bdfdrivr.c (BDF_Face_Init): Replace calls to FT_ABS with direct code to avoid value negation. * src/cff/cf2blues.c (cf2_blues_capture): Use SUB_INT32 and ADD_INT32.
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
diff --git a/ChangeLog b/ChangeLog
index 74dc50f..e4a4db9 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,18 @@
+2017-06-15 Werner Lemberg <wl@gnu.org>
+
+ [bdf, cff] Integer overflows.
+
+ Reported as
+
+ https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=2244
+ https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=2261
+
+ * src/bdf/bdfdrivr.c (BDF_Face_Init): Replace calls to FT_ABS with
+ direct code to avoid value negation.
+
+ * src/cff/cf2blues.c (cf2_blues_capture): Use SUB_INT32 and
+ ADD_INT32.
+
2017-06-13 Werner Lemberg <wl@gnu.org>
* src/winfonts/winfnt.c (FNT_Face_Init): Don't set active encoding.
diff --git a/src/bdf/bdfdrivr.c b/src/bdf/bdfdrivr.c
index 09cb489..37e6eea 100644
--- a/src/bdf/bdfdrivr.c
+++ b/src/bdf/bdfdrivr.c
@@ -442,13 +442,13 @@ THE SOFTWARE.
FT_ZERO( bsize );
/* sanity checks */
- if ( FT_ABS( font->font_ascent ) > 0x7FFF )
+ if ( font->font_ascent > 0x7FFF || font->font_ascent < -0x7FFF )
{
font->font_ascent = font->font_ascent < 0 ? -0x7FFF : 0x7FFF;
FT_TRACE0(( "BDF_Face_Init: clamping font ascent to value %d\n",
font->font_ascent ));
}
- if ( FT_ABS( font->font_descent ) > 0x7FFF )
+ if ( font->font_descent > 0x7FFF || font->font_descent < -0x7FFF )
{
font->font_descent = font->font_descent < 0 ? -0x7FFF : 0x7FFF;
FT_TRACE0(( "BDF_Face_Init: clamping font descent to value %d\n",
@@ -464,7 +464,8 @@ THE SOFTWARE.
if ( prop->value.l < 0 )
FT_TRACE0(( "BDF_Face_Init: negative average width\n" ));
#endif
- if ( ( FT_ABS( prop->value.l ) > 0x7FFFL * 10 - 5 ) )
+ if ( prop->value.l > 0x7FFFL * 10 - 5 ||
+ prop->value.l < -( 0x7FFFL * 10 - 5 ) )
{
bsize->width = 0x7FFF;
FT_TRACE0(( "BDF_Face_Init: clamping average width to value %d\n",
@@ -487,7 +488,8 @@ THE SOFTWARE.
FT_TRACE0(( "BDF_Face_Init: negative point size\n" ));
#endif
/* convert from 722.7 decipoints to 72 points per inch */
- if ( FT_ABS( prop->value.l ) > 0x504C2L ) /* 0x7FFF * 72270/7200 */
+ if ( prop->value.l > 0x504C2L || /* 0x7FFF * 72270/7200 */
+ prop->value.l < -0x504C2L )
{
bsize->size = 0x7FFF;
FT_TRACE0(( "BDF_Face_Init: clamping point size to value %d\n",
@@ -511,7 +513,7 @@ THE SOFTWARE.
if ( prop->value.l < 0 )
FT_TRACE0(( "BDF_Face_Init: negative pixel size\n" ));
#endif
- if ( FT_ABS( prop->value.l ) > 0x7FFF )
+ if ( prop->value.l > 0x7FFF || prop->value.l < -0x7FFF )
{
bsize->y_ppem = 0x7FFF << 6;
FT_TRACE0(( "BDF_Face_Init: clamping pixel size to value %d\n",
@@ -528,7 +530,7 @@ THE SOFTWARE.
if ( prop->value.l < 0 )
FT_TRACE0(( "BDF_Face_Init: negative X resolution\n" ));
#endif
- if ( FT_ABS( prop->value.l ) > 0x7FFF )
+ if ( prop->value.l > 0x7FFF || prop->value.l < -0x7FFF )
{
resolution_x = 0x7FFF;
FT_TRACE0(( "BDF_Face_Init: clamping X resolution to value %d\n",
@@ -545,7 +547,7 @@ THE SOFTWARE.
if ( prop->value.l < 0 )
FT_TRACE0(( "BDF_Face_Init: negative Y resolution\n" ));
#endif
- if ( FT_ABS( prop->value.l ) > 0x7FFF )
+ if ( prop->value.l > 0x7FFF || prop->value.l < -0x7FFF )
{
resolution_y = 0x7FFF;
FT_TRACE0(( "BDF_Face_Init: clamping Y resolution to value %d\n",
diff --git a/src/cff/cf2blues.c b/src/cff/cf2blues.c
index 5ba5f9c..f5b44b2 100644
--- a/src/cff/cf2blues.c
+++ b/src/cff/cf2blues.c
@@ -489,10 +489,10 @@
if ( blues->zone[i].bottomZone &&
cf2_hint_isBottom( bottomHintEdge ) )
{
- if ( ( blues->zone[i].csBottomEdge - csFuzz ) <=
- bottomHintEdge->csCoord &&
+ if ( SUB_INT32( blues->zone[i].csBottomEdge, csFuzz ) <=
+ bottomHintEdge->csCoord &&
bottomHintEdge->csCoord <=
- ( blues->zone[i].csTopEdge + csFuzz ) )
+ ADD_INT32( blues->zone[i].csTopEdge, csFuzz ) )
{
/* bottom edge captured by bottom zone */
@@ -524,10 +524,10 @@
if ( !blues->zone[i].bottomZone && cf2_hint_isTop( topHintEdge ) )
{
- if ( ( blues->zone[i].csBottomEdge - csFuzz ) <=
- topHintEdge->csCoord &&
+ if ( ( SUB_INT32( blues->zone[i].csBottomEdge, csFuzz ) ) <=
+ topHintEdge->csCoord &&
topHintEdge->csCoord <=
- ( blues->zone[i].csTopEdge + csFuzz ) )
+ ADD_INT32( blues->zone[i].csTopEdge, csFuzz ) )
{
/* top edge captured by top zone */