bugThe FreeType Project - Bugs: bug #48732, Should FT_F26Dot6, FT_Fixed etc....

 
 

bug #48732: Should FT_F26Dot6, FT_Fixed etc. be always 32 bits long?

Submitted by:  None
Submitted on:  Tue 09 Aug 2016 03:12:48 PM UTC  
 
Severity: 3 - NormalItem Group: None
Status: FixedPrivacy: Public
Assigned to: Werner LEMBERG <wl>Open/Closed: Closed
Planned Release: 2.7.0

Add a New Comment(Rich Markup)
   

You are not logged in

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

 

Wed 10 Aug 2016 05:50:12 PM UTC, comment #3:

Well, it was a simple bug, not noticed for 16 years, and now fixed in git.

Thanks for the report!

Werner LEMBERG <wl>
Project AdministratorIn charge of this item.
Wed 10 Aug 2016 12:08:54 PM UTC, comment #2:

Sorry for not explaining better what the problem is.

Steps to reproduce:
1. Build FreeType on a 64-bit platform.
2. Load some italic font into FreeType. For example, the /Library/Fonts/Arial Italic.ttf which ships with MacOS. But any other forward-leaning italic font will trigger this bug, so it does not matter which font you take.
3. Ask FreeType for the PostScript table.
4. Inspect the value of its italicAngle field.

Observed:
post->italicAngle is a signed 64-bit integer 0x00000000fff40000, which is a very large positive value. (On a 32-bit platform, it would have been signed 32-bit integer 0xfff40000, which is a negative value).

Expected:
Ideally, post->italicAngle would be a signed 32-bit integer also on 64-bit platforms. But making this change would break FreeType's binary API, so it's probably too disruptive. Alternatively, post->italicAngle could be sign-extended so its value would be the signed 64-bit integer 0xfffffffffff40000. That would be a negative value with the same numeric interpretation as the 32-bit integer 0xfff40000.

The same problem probably exists with other FT_Fixed and FT_F26Dot6 fields, so it's probably not just italicAngle.

-- Sascha

Anonymous
Wed 10 Aug 2016 07:32:02 AM UTC, comment #1:

I don't fully understand the problem. You have a 64bit version of the library, and `static_cast' fails within a 64bit application?

You have to use the same compiler for both library and application to make `FT_Get_Sfnt_Table' work. Otherwise there is no guarantee to get the same offsets to a structure's member; AFAIK, this is undefined in the C (and C++) standard. (I should probably document this better.)

Irrespective of that, I would really like to change the type of many structure members to correct mistakes that accumulated over the years, but I can't do that for backwards compatibility.

Werner LEMBERG <wl>
Project AdministratorIn charge of this item.
Tue 09 Aug 2016 03:12:48 PM UTC, original submission:

Currently, FT_F26Dot6 and FT_Fixed are typedef’d to signed long. Should they be defined instead to FT_Int32?

I had a subtle bug in my application code, where I was trying to find the italic angle of a FreeType face like this:

double angle = 0.0;
TT_Postscript* post =
static_cast<TT_Postscript*>(FT_Get_Sfnt_Table(face, ft_sfnt_post));
if (post) {
angle = post->italicAngle / 65536.0;
}

However, this gives the wrong result on 64-bit platforms. Of course one can work around this, eg. with "static_cast<int32_t>(post->italicAngle) / 65536.0". On the other hand, I was rather surprised to find that FT_F26Dot6 and FT_Fixed can be 64 bits long on certain platforms; and it’s often not ideal when programmers are surprised.

— Sascha, -unavailable-

Anonymous

 

(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)
  •  

    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 5 latest changes.

    Date Changed By Updated Field Previous Value => Replaced By
    Wed 10 Aug 2016 05:50:12 PM UTCwlStatusNeed Info=>Fixed
      Open/ClosedOpen=>Closed
      Planned ReleaseNone=>2.7.0
    Wed 10 Aug 2016 07:32:02 AM UTCwlStatusNone=>Need Info
      Assigned toNone=>wl

    Back to the top


    Powered by Savane 3.1-cleanup1