bugThe FreeType Project - Bugs: bug #51992, TrueType FT_Get_Char_Index bad...

 
 

bug #51992: TrueType FT_Get_Char_Index bad implicit pointer cast.

Submitted by:  gcl@bigvikinggames.com <guillaumecl>
Submitted on:  Mon 11 Sep 2017 08:33:51 PM UTC  
 
Severity: 3 - NormalItem Group: Incorrect behaviour
Status: InvalidPrivacy: 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.

 

Mon 11 Sep 2017 10:11:37 PM UTC, comment #2:

Ah, nevermind, I've found the issue and it was with assumed ownership of the memory for the face needs. I've fixed it locally. That said, the FT_CMap to TT_CMap implicit case is still really sketchy.

This bug can be closed.

gcl@bigvikinggames.com <guillaumecl>
Mon 11 Sep 2017 10:11:16 PM UTC, comment #1:

There is a FreeType demo program, ftdiff, that uses FT_Get_Char_Index. It works without problems using your test font.

Regarding the structure conversion: FT_CMap is the `base' class, and TT_CMap is derived from it; it contains an FT_CMap object as its first element. This is the standard solution for emulating C++'s class inheritance and used everywhere in FreeType!

I thus suspect there is a bug somewhere in your program, maybe related to calling C code from C++. However, if you still think there is a bug in Freetype, please provide a small stand-alone, TTY-based, compilable program that exhibits the problem, and reopen this issue.

Werner LEMBERG <wl>
Project AdministratorIn charge of this item.
Mon 11 Sep 2017 08:33:51 PM UTC, original submission:

I've been trying to get a truetype font to display with 2.8 for the past few days and I've run into an annoying bug. It seems that FT_Get_Char_Index doesn't work as expected, returning 0 for every char, and I think I've discovered why.

In FT_Get_Char_Index the call is done like so:
result = cmap->clazz->char_index( cmap, (FT_UInt32)charcode );
Where cmap is defined as an FT_CMap like so:
FT_CMap cmap = FT_CMAP( face->charmap );

The TT function that gets called to do the lookup in ttcmap.c is
FT_CALLBACK_DEF( FT_UInt )
tt_cmap4_char_index( TT_CMap cmap,
FT_UInt32 char_code )

This expects a TT_CMap not an FT_CMap. The conversion seems to still be allowed, but looking at both structs, there's no way that this conversion can work properly. As such, in the binary search that the TT code does, the p pointer for the data is well off into memory it shouldn't be.

I've included the font I've been using for diagnostic and I've been calling the code like so:

// activate the size and create the glyph
THOR_LOG("Activating size: faceHeight %d, numGlyphs %d", (size)->face->height, (size)->face->num_glyphs);
FT_Error error = FT_Activate_Size(*size);
if (error) {
LOG("Could not activate size to get character data for character '%c', got error %#02x.", character, error);
return &FontCharacter::NULL_CHARACTER;
}

error = FT_Load_Char(face, character, FT_LOAD_DEFAULT);
if (error) {
LOG("Could not load glyph '%c', got error %#02x.", character, error);
return &FontCharacter::NULL_CHARACTER;
}

error = FT_Render_Glyph(face->glyph, FT_RENDER_MODE_NORMAL);
if (error) {
LOG("Could not render glyph '%c', got error %#02x.", character, error);
return &FontCharacter::NULL_CHARACTER;
}

gcl@bigvikinggames.com <guillaumecl>

 

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

Attach File(s):
   
   
Comment:
   

Attached Files
file #41780:  CaviarDreams.ttf added by guillaumecl (57KiB - application/octet-stream)

 

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 guillaumecl (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 4 latest changes.

    Date Changed By Updated Field Previous Value => Replaced By
    Mon 11 Sep 2017 10:11:16 PM UTCwlStatusNone=>Invalid
      Assigned toNone=>wl
      Open/ClosedOpen=>Closed
    Mon 11 Sep 2017 08:33:51 PM UTCguillaumeclAttached File-=>Added CaviarDreams.ttf, #41780

    Back to the top


    Powered by Savane 3.1-cleanup1