[psaux] Fix some value overflows. * src/psaux/psconv.c (PS_Conv_ToFixed): Implement it.
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
diff --git a/ChangeLog b/ChangeLog
index 1e8975d..d9fb1a6 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2012-10-17 Werner Lemberg <wl@gnu.org>
+
+ [psaux] Fix some value overflows.
+
+ * src/psaux/psconv.c (PS_Conv_ToFixed): Implement it.
+
2012-10-17 Bram Tassyns <BramT@enfocus.com>
[cff] Fix value overflow.
diff --git a/src/psaux/psconv.c b/src/psaux/psconv.c
index 9ea7fb9..df53083 100644
--- a/src/psaux/psconv.c
+++ b/src/psaux/psconv.c
@@ -163,7 +163,14 @@
}
if ( *p != '.' )
- integral = PS_Conv_ToInt( &p, limit ) << 16;
+ {
+ integral = PS_Conv_ToInt( &p, limit );
+
+ if ( integral > 0x7FFF )
+ return sign ? -0x7FFFFFFFL : 0x7FFFFFFFL;
+
+ integral <<= 16;
+ }
else
integral = 0;
@@ -210,6 +217,8 @@
while ( power_ten > 0 )
{
+ if ( integral >= 0xCCCCCCCL )
+ return sign ? -0x7FFFFFFFL : 0x7FFFFFFFL;
integral *= 10;
decimal *= 10;
power_ten--;
@@ -223,7 +232,12 @@
}
if ( decimal )
- integral += FT_DivFix( decimal, divider );
+ {
+ decimal = FT_DivFix( decimal, divider );
+ if ( 0x7FFFFFFFL - decimal < integral )
+ return sign ? -0x7FFFFFFFL : 0x7FFFFFFFL;
+ integral += decimal;
+ }
if ( sign )
integral = -integral;