From 77c39b1deb0d44f1a642335ae72af66b91271cf9 Mon Sep 17 00:00:00 2001 From: Werner Lemberg Date: Sat, 4 May 2013 18:04:07 +0200 Subject: [PATCH] [cff] Make Adobe CFF engine work correctly on 64bit hosts. Reported by numerous people on the `freetype-devel' list. Without this fix, glyphs aren't properly aligned on a common baseline. On 64bit systems, `FT_Pos' expands to `long int', having a width of 64bit. `CF2_Fixed' expands to `int' which is normally 32bit wide on 64bit hosts also. Wrong casts filled up the blues arrays with incorrect values. Note that all blues values are accessed with the `cf2_blueToFixed' macro which handles the 64bit to 32bit conversion. * src/cff/cf2ft.h (cf2_getBlueValues, cf2_getOtherBlues, cf2_getFamilyBlues, cf2_getFamilyOtherBlues): Use `FT_Pos' for `data', not `CF2_Fixed'. * src/cff/cf2ft.c (cf2_getBlueValues, cf2_getOtherBlues, cf2_getFamilyBlues, cf2_getFamilyOtherBlues): Updated. * src/cff/cf2blues.c (cf2_blues_init): Updated. --- ChangeLog | 22 +++++++++++++++++++++- src/cff/cf2blues.c | 8 ++++---- src/cff/cf2ft.c | 16 ++++++++-------- src/cff/cf2ft.h | 8 ++++---- 4 files changed, 37 insertions(+), 17 deletions(-) diff --git a/ChangeLog b/ChangeLog index 11ab58422..765fd6eb2 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,23 @@ +2013-05-04 Werner Lemberg + + [cff] Make Adobe CFF engine work correctly on 64bit hosts. + + Reported by numerous people on the `freetype-devel' list. Without + this fix, glyphs aren't properly aligned on a common baseline. + + On 64bit systems, `FT_Pos' expands to `long int', having a width of + 64bit. `CF2_Fixed' expands to `int' which is normally 32bit wide on + 64bit hosts also. Wrong casts filled up the blues arrays with + incorrect values. Note that all blues values are accessed with the + `cf2_blueToFixed' macro which handles the 64bit to 32bit conversion. + + * src/cff/cf2ft.h (cf2_getBlueValues, cf2_getOtherBlues, + cf2_getFamilyBlues, cf2_getFamilyOtherBlues): Use `FT_Pos' for + `data', not `CF2_Fixed'. + * src/cff/cf2ft.c (cf2_getBlueValues, cf2_getOtherBlues, + cf2_getFamilyBlues, cf2_getFamilyOtherBlues): Updated. + * src/cff/cf2blues.c (cf2_blues_init): Updated. + 2013-05-04 Werner Lemberg More fixes for clang's `sanitize' feature. @@ -537,7 +557,7 @@ [sfnt] Fix broken pointer overflow checks. Many compilers such as gcc and clang optimize away pointer overflow - checks `p + n < p', because pointer overflow is undefined behavior. + checks `p + n < p', because pointer overflow is undefined behavior. Use a safe form `n > p_limit - p' instead. Also avoid possible integer overflow issues, for example, using diff --git a/src/cff/cf2blues.c b/src/cff/cf2blues.c index 958b09816..5b348398a 100644 --- a/src/cff/cf2blues.c +++ b/src/cff/cf2blues.c @@ -78,10 +78,10 @@ size_t numFamilyBlues; size_t numFamilyOtherBlues; - CF2_Fixed* blueValues; - CF2_Fixed* otherBlues; - CF2_Fixed* familyBlues; - CF2_Fixed* familyOtherBlues; + FT_Pos* blueValues; + FT_Pos* otherBlues; + FT_Pos* familyBlues; + FT_Pos* familyOtherBlues; size_t i; CF2_Fixed emBoxBottom, emBoxTop; diff --git a/src/cff/cf2ft.c b/src/cff/cf2ft.c index 331eda07d..9b6087f2d 100644 --- a/src/cff/cf2ft.c +++ b/src/cff/cf2ft.c @@ -432,12 +432,12 @@ FT_LOCAL_DEF( void ) cf2_getBlueValues( CFF_Decoder* decoder, size_t* count, - CF2_Fixed* *data ) + FT_Pos* *data ) { FT_ASSERT( decoder && decoder->current_subfont ); *count = decoder->current_subfont->private_dict.num_blue_values; - *data = (CF2_Fixed*) + *data = (FT_Pos*) &decoder->current_subfont->private_dict.blue_values; } @@ -445,12 +445,12 @@ FT_LOCAL_DEF( void ) cf2_getOtherBlues( CFF_Decoder* decoder, size_t* count, - CF2_Fixed* *data ) + FT_Pos* *data ) { FT_ASSERT( decoder && decoder->current_subfont ); *count = decoder->current_subfont->private_dict.num_other_blues; - *data = (CF2_Fixed*) + *data = (FT_Pos*) &decoder->current_subfont->private_dict.other_blues; } @@ -458,12 +458,12 @@ FT_LOCAL_DEF( void ) cf2_getFamilyBlues( CFF_Decoder* decoder, size_t* count, - CF2_Fixed* *data ) + FT_Pos* *data ) { FT_ASSERT( decoder && decoder->current_subfont ); *count = decoder->current_subfont->private_dict.num_family_blues; - *data = (CF2_Fixed*) + *data = (FT_Pos*) &decoder->current_subfont->private_dict.family_blues; } @@ -471,12 +471,12 @@ FT_LOCAL_DEF( void ) cf2_getFamilyOtherBlues( CFF_Decoder* decoder, size_t* count, - CF2_Fixed* *data ) + FT_Pos* *data ) { FT_ASSERT( decoder && decoder->current_subfont ); *count = decoder->current_subfont->private_dict.num_family_other_blues; - *data = (CF2_Fixed*) + *data = (FT_Pos*) &decoder->current_subfont->private_dict.family_other_blues; } diff --git a/src/cff/cf2ft.h b/src/cff/cf2ft.h index 0d13702dd..731da3ca8 100644 --- a/src/cff/cf2ft.h +++ b/src/cff/cf2ft.h @@ -80,19 +80,19 @@ FT_BEGIN_HEADER FT_LOCAL( void ) cf2_getBlueValues( CFF_Decoder* decoder, size_t* count, - CF2_Fixed* *data ); + FT_Pos* *data ); FT_LOCAL( void ) cf2_getOtherBlues( CFF_Decoder* decoder, size_t* count, - CF2_Fixed* *data ); + FT_Pos* *data ); FT_LOCAL( void ) cf2_getFamilyBlues( CFF_Decoder* decoder, size_t* count, - CF2_Fixed* *data ); + FT_Pos* *data ); FT_LOCAL( void ) cf2_getFamilyOtherBlues( CFF_Decoder* decoder, size_t* count, - CF2_Fixed* *data ); + FT_Pos* *data ); FT_LOCAL( CF2_Int ) cf2_getLanguageGroup( CFF_Decoder* decoder );