bugThe FreeType Project - Bugs: bug #40481, Incorrect FT_Load_Sfnt_Table for...

 
 

bug #40481: Incorrect FT_Load_Sfnt_Table for Linux 64 bit

Submitted by:  Eugene Egorov <eugeneegorov>
Submitted on:  Tue 05 Nov 2013 01:01:44 PM UTC  
 
Severity: 3 - NormalItem Group: Incorrect behaviour
Status: DuplicatePrivacy: Public
Assigned to: Werner LEMBERG <wl>Open/Closed: Closed
Planned Release: None

Add a New Comment(Rich Markup)
   

You are not logged in

Please log in, so followups can be emailed to you.

 

Wed 06 Nov 2013 03:56:00 AM UTC, comment #3:

Ok, got it, the comment makes things clear. Thank you!

Eugene Egorov <eugeneegorov>
Tue 05 Nov 2013 10:47:40 PM UTC, comment #2:

I've added a comment to FT_Load_Sfnt_Table to clarify the issue.

Werner LEMBERG <wl>
Project AdministratorIn charge of this item.
Tue 05 Nov 2013 10:29:42 PM UTC, comment #1:

Thanks for the report, However, it is invalid, as far as I can see. Please look at bug #39407; it hopefully explains the issue.

Werner LEMBERG <wl>
Project AdministratorIn charge of this item.
Tue 05 Nov 2013 01:01:44 PM UTC, original submission:

Hello,

We've faced several problems with freetype compiled on Linux 64bit(Ubuntu 10.04).

1) FT_Load_Sfnt_Table works incorrectly for at least tables TT_Header and TT_HoriHeader. The reason is wrong offsets of struct members.

typedef struct TT_Header_
{
FT_Fixed Table_Version;
FT_Fixed Font_Revision;

FT_Long CheckSum_Adjust;
FT_Long Magic_Number;

FT_UShort Flags;
FT_UShort Units_Per_EM;

FT_Long Created [2];
FT_Long Modified[2];
...
It seems to be FT_Fixed and FT_Long types should be of size 4. But in fttypes.h they are defined as:
typedef signed long FT_Long;
typedef signed long FT_Fixed;
sizeof(long) for 64bit Linux is 8.
The most obvious way to fix it is to redefine FT_Fixed and FT_Long(and maybe FT_ULong just in case) like
typedef signed int FT_Long; // etc
Also there is a good idea about compile time checking offsets in tables.
c++0x has static_assert expr for this, but in earlier versions this can be easily done like this:
char some_unique_name[ ( <some constant expression> ) ? 1 : -1 ];
For example this check will preserve shifting offsets in struct on any platform:
extern int offsetin_TT_Header_[ ( offsetof(TT_Header,Glyph_Data_Format) == 52 ) ? 1 : -1 ];
and for HoriHeader:
extern int sizeof_TT_HoriHeader[ ( offsetof(TT_HoriHeader, number_Of_HMetrics) == 34 ) ? 1 : -1 ];

2) The same problem is for TT_OS2 table. Size of and offsets in this struct are critical. Here are some static_asserts to force offsets in TT_OS2 to be correct:
extern int offsetin_TT_OS2[ ( offsetof(TT_OS2, ulUnicodeRange1) == 42 ) ? 1 : -1 ];
extern int offsetin_TT_OS2_2[ ( offsetof(TT_OS2, fsSelection) == 62 ) ? 1 : -1 ];
extern int offsetin_TT_OS2_3[ ( offsetof(TT_OS2, usMaxContext) == 94 ) ? 1 : -1 ];
To fix sizeof(FT_Long) is not always enough, this struct should be packed to match requirements above. For gcc this may be fixed like this:
typedef struct _attribute_ ((_packed_)) TT_OS2_
{
...

Hope you'll fix this in the next version, thanks!

Eugene

Eugene Egorov <eugeneegorov>

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach File(s):
   
   
Comment:
   

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -unavailable- added by wl (Posted a comment)
  • -unavailable- added by eugeneegorov (Submitted the item)
  • -unavailable- added by eugeneegorov
  •  

    Do you think this task is very important?
    If so, you can click here to add your encouragement to it.
    This task has 0 encouragements so far.

    Only logged-in users can vote.

     

    Please enter the title of George Orwell's famous dystopian book (it's a date):

     

     

    Follow 4 latest changes.

    Date Changed By Updated Field Previous Value => Replaced By
    Tue 05 Nov 2013 10:29:42 PM UTCwlStatusNone=>Duplicate
      Assigned toNone=>wl
      Open/ClosedOpen=>Closed
    Tue 05 Nov 2013 01:01:44 PM UTCeugeneegorovCarbon-Copy-=>Added eugeneegorov

    Back to the top


    Powered by Savane 3.1-cleanup1