* src/base/ftcalc.c (FT_Matrix_Check): Fix integer overflow. Reported as https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=9811
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
diff --git a/ChangeLog b/ChangeLog
index 11f2de4..6f2ca3f 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2018-08-11 Werner Lemberg <wl@gnu.org>
+
+ * src/base/ftcalc.c (FT_Matrix_Check): Fix integer overflow.
+
+ Reported as
+
+ https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=9811
+
2018-08-10 Alexei Podtelezhnikov <apodtele@gmail.com>
* src/sfnt/ttsbit.c (tt_sbit_decoder_load_compound): Follow specs.
diff --git a/include/freetype/freetype.h b/include/freetype/freetype.h
index 620df4c..fa937cd 100644
--- a/include/freetype/freetype.h
+++ b/include/freetype/freetype.h
@@ -4669,6 +4669,11 @@ FT_BEGIN_HEADER
* This section contains various functions used to perform
* computations on 16.16 fixed-float numbers or 2d vectors.
*
+ * *Attention*: Most arithmetic functions take `FT_Long' as arguments.
+ * For historical reasons, FreeType was designed under the assumption
+ * that `FT_Long' is a 32-bit integer; results can thus be undefined
+ * if the arguments don't fit into 32 bits.
+ *
* @order:
* FT_MulDiv
* FT_MulFix
diff --git a/src/base/ftcalc.c b/src/base/ftcalc.c
index c96d5d2..2cea03c 100644
--- a/src/base/ftcalc.c
+++ b/src/base/ftcalc.c
@@ -701,8 +701,8 @@
if ( !delta )
return FT_THROW( Invalid_Argument ); /* matrix can't be inverted */
- matrix->xy = - FT_DivFix( matrix->xy, delta );
- matrix->yx = - FT_DivFix( matrix->yx, delta );
+ matrix->xy = -FT_DivFix( matrix->xy, delta );
+ matrix->yx = -FT_DivFix( matrix->yx, delta );
xx = matrix->xx;
yy = matrix->yy;
@@ -784,6 +784,10 @@
nonzero_minval = val[i];
}
+ /* we only handle 32bit values */
+ if ( maxval > 0x7FFFFFFFL )
+ return 0;
+
if ( maxval > 23170 )
{
FT_Fixed scale = FT_DivFix( maxval, 23170 );