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

 
 

You are not allowed to post comments on this tracker with your current authentication level.

bug #39407: TT_OS2 alignment problem

Submitter:  Ted Dunlop <teddunlop>
Submitted:  Wed 03 Jul 2013 02:46:50 PM UTC
   
 
Severity:  3 - Normal Item Group:  Hack required
Status:  Invalid Privacy:  Public
Assigned to:  wl Open/Closed:  Closed
Planned Release:  None

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>
Group administrator
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>
Group administrator
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>
Group administrator
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.)

Attached Files
file #28772:  adfreetype.cpp added by teddunlop (7KiB - 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 (3KiB - 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
  • -email is unavailable- added by wl (Posted a comment)
  • -email is unavailable- added by teddunlop (Submitted the item)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

     

    Follow 6 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2013-08-06 teddunlop Attached File- Added adfreetype.cpp, #28772
        Attached File- Added adfreetype.h, #28773
    2013-08-05 wl StatusNeed Info Invalid
        Open/ClosedOpen Closed
    2013-07-03 wl StatusNone Need Info
        Assigned toNone wl

    Back to the top

    Powered by Savane 3.13-758e.
    Corresponding source code