bugThe FreeType Project - Bugs: bug #39407, TT_OS2 alignment problem

 
 

bug #39407: TT_OS2 alignment problem

Submitted by:  Ted Dunlop <teddunlop>
Submitted on:  Wed 03 Jul 2013 02:46:50 PM UTC  
 
Severity: 3 - NormalItem Group: Hack required
Status: InvalidPrivacy: Public
Assigned to: Werner LEMBERG <wl>Open/Closed: Closed
Planned Release: None

Add a New Comment (Rich MarkupRich Markup):
   

You are not logged in

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

 

Tue 06 Aug 2013 07:05:18 PM UTC, comment #4:

Yes,in your code you assume that

sizeof (TT_OS2) == fontTable_.Size()

which is not correct. For example, in OS2Table::Panose(),
you can't use `offsetof' applied to the `TT_OS2' structure to get the offset into the Panose table within the `OS/2' SFNT table. Instead, you should manually set the offset, something like

const int versionOfset = 0;
const int xAvgCharWidthOffset = 2;
const int usWeightClassOffset = 4;
...
const int panoseOffset = 32;
...

and use those constants.

Werner LEMBERG <wl>
Project AdministratorIn charge of this item.
Mon 05 Aug 2013 03:00:07 PM UTC, comment #3:

As I said before: You can't apply the offsets of the `TT_OS2' structure to the data which you directly extract from an SFNT table.

If you access an SFNT table directly, you get the layout as described in the OpenType specification, this is, you should use manually calculate byte offsets and use big-endian stuff to access 16bit and 32bit values.

If you access a data structure provided by FreeType, `offsetof' should be just fine to directly access the values.

Werner LEMBERG <wl>
Project AdministratorIn charge of this item.
Wed 31 Jul 2013 08:12:44 PM UTC, comment #2:

I must be missing something:

There are 16 two byte big endian integers preceding the panose field. The panose field is 10 bytes long. 2 * 16 + 10 = 42. The next field ulUnicodeRange1 is a 4 byte big endian integer. When the structure is left aligned on default boundaries, the offset to ulUnicodeRange1 is 44. When packed it is 42. When I pack the table, I get the proper offsets to fields following the panose number. If I don't I get improper values.

Below demonstrates how I accessed the fields. Perhaps I missed a method to retrieve the individual fields or to retrieve a copy of the re-organized table. Could you please indicate where I went wrong?

size_t oulRange1 = offsetof(TT_OS2_, TT_OS2_::ulUnicodeRange1);
const unsigned char* t = fontTable_.Table ( ) + oulRange1;
return ReturnTTUnsignedLongAsUnsignedLong (t);

Regards

Ted Dunlop <teddunlop>
Wed 03 Jul 2013 08:21:30 PM UTC, comment #1:

What do you mean with `not aligned correctly'? Your pragma hack is definitely wrong. The TT_OS2 structure does not have the same physical layout as the data in the font's `OS/2' table, and the structure elements are read one after another from the font into the structure.

Werner LEMBERG <wl>
Project AdministratorIn charge of this item.
Wed 03 Jul 2013 02:46:50 PM UTC, original submission:

fields after panose not aligned correctly in TT_OS2

Problem is that ulUnicodeRange1 is not properly aligned.

requires #pragma pack(2) directive to precede table definition
e.g.
#pragma pack(2)
typedef struct TT_OS2_
{
...
} TT_OS2;
#pragma pack

workaround for API clients is:

#pragma pack(2)
#include FT_TRUETYPE_TABLES
#pragma pack

Ted Dunlop <teddunlop>

 

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

Attach File(s):
   
   
Comment:
   

Attached Files
file #28772:  adfreetype.cpp added by teddunlop (7kB - text/plain - Here is the code that prompted my initial concern, I believe that it loads the OS2 table using the appropriate API call)
file #28773:  adfreetype.h added by teddunlop (3kB - text/plain - Here is the code that prompted my initial concern, I believe that it loads the OS2 table using the appropriate API call)

 

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 teddunlop (Submitted the item)
  •  

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

    Date Changed By Updated Field Previous Value => Replaced By
    Tue 06 Aug 2013 01:38:44 PM UTCteddunlopAttached File-=>Added adfreetype.cpp, #28772
      Attached File-=>Added adfreetype.h, #28773
    Mon 05 Aug 2013 03:00:07 PM UTCwlStatusNeed Info=>Invalid
      Open/ClosedOpen=>Closed
    Wed 03 Jul 2013 08:21:30 PM UTCwlStatusNone=>Need Info
      Assigned toNone=>wl

    Back to the top


    Powered by Savane 3.1-cleanup