#26 crashes on utf-8

open
nobody
None
5
2010-08-01
2010-08-01
Kai-Uwe Behrmann
No

FTGL crashes while rendering non english utf-8.

reproduce:
demo/FTGLDemo
press Del
type non english character, e.g. ü (german Umlaut)
crash

expected behaviour:
no crash

Discussion

  • Sean Morrison
    Sean Morrison
    2010-08-20

    If you provide a stack trace, that would help. You can get a trace by running FTGLDemo in gdb or another debugger and provoking the crash.

    gdb --args demo/FTGLDemo
    run
    [make it crash]
    backtrace

     
  • The back trace follows:

    Program received signal SIGSEGV, Segmentation fault.
    0x00007ffff7979249 in find (c=<value optimized out>,
    this=<value optimized out>) at FTCharToGlyphIndexMap.h:109
    109 FTCharToGlyphIndexMap.h: Datei oder Verzeichnis nicht gefunden.
    in FTCharToGlyphIndexMap.h
    (gdb) bt
    #0 0x00007ffff7979249 in find (c=<value optimized out>,
    this=<value optimized out>) at FTCharToGlyphIndexMap.h:109
    #1 FTCharmap::GlyphListIndex (c=<value optimized out>,
    this=<value optimized out>) at FTCharmap.cpp:86
    #2 0x00007ffff797c79d in FTGlyphContainer::Glyph (this=0x7eddf0, charCode=256)
    at FTGlyphContainer.cpp:81
    #3 0x00007ffff798356f in FTFontImpl::CheckGlyph (this=0x7c9810,
    characterCode=256) at FTFont/FTFont.cpp:524
    #4 0x00007ffff7984d89 in BBoxI<unsigned char> (spacing=<value optimized out>,
    position=<value optimized out>, len=<value optimized out>,
    string=<value optimized out>, this=<value optimized out>)
    at FTFont/FTFont.cpp:391
    #5 FTFontImpl::BBox (spacing=<value optimized out>,
    position=<value optimized out>, len=<value optimized out>,
    string=<value optimized out>, this=<value optimized out>)
    at FTFont/FTFont.cpp:427
    #6 0x00007ffff7983483 in FTFont::BBox (this=<value optimized out>,
    string=0x7f92d1 "", len=8360657, position=..., spacing=...)
    at FTFont/FTFont.cpp:193
    #7 0x00007ffff798ccc9 in WrapTextI<char> (bounds=<value optimized out>,
    renderMode=<value optimized out>, position=..., len=<value optimized out>,
    buf=<value optimized out>, this=<value optimized out>)
    at FTLayout/FTSimpleLayout.cpp:223
    ---Type <return> to continue, or q <return> to quit---
    #8 FTSimpleLayoutImpl::WrapText (bounds=<value optimized out>,
    renderMode=<value optimized out>, position=..., len=<value optimized out>,
    buf=<value optimized out>, this=<value optimized out>)
    at FTLayout/FTSimpleLayout.cpp:322
    #9 0x0000000000404d46 in do_display () at FTGLDemo.cpp:427
    #10 0x00000000004050a3 in display () at FTGLDemo.cpp:477
    #11 0x00007ffff7bb92ed in ?? () from /usr/lib64/libglut.so.3
    #12 0x00007ffff7bbcb99 in fgEnumWindows () from /usr/lib64/libglut.so.3
    #13 0x00007ffff7bb97b2 in glutMainLoopEvent () from /usr/lib64/libglut.so.3
    #14 0x00007ffff7bba107 in glutMainLoop () from /usr/lib64/libglut.so.3
    #15 0x0000000000405d77 in main (argc=1, argv=0x7fffffffd9b8)
    at FTGLDemo.cpp:738
    (gdb)

     
  • Sean Morrison
    Sean Morrison
    2010-08-20

    Thanks for the stack trace! The demo can be changed, but the library still shouldn't crash.

     

  • Anonymous
    2013-01-08

    I had the same problem. The crash was due to two places where you can get a NULL pointer: Glyph(charCode) and charMap->GlyphListIndex(charCode) returns 0 on errors, so using its result if 0 is not a good idea...

    My fix was in FTGlyphContainer.cpp, my patch is

    @@ -80,13 +80,21 @@
    {
    unsigned int index = charMap->GlyphListIndex(charCode);

    + // NOTE GlyphListIndex() returns 0 if not found.
    + // glyphs[0] is NULL, thus we save the test for those rare cases.
    return (index < glyphs.size()) ? glyphs[index] : NULL;
    }

    FTBBox FTGlyphContainer::BBox(const unsigned int charCode) const
    {
    - return Glyph(charCode)->BBox();
    + const FTGlyph *glyph = Glyph(charCode);
    +
    + if (!glyph)
    + {
    + return FTBBox();
    + }
    + return glyph->BBox();
    }

    and in FTPoint FTGlyphContainer::Render:

    @@ -116,7 +124,7 @@
    if(!face->Error())
    {
    unsigned int index = charMap->GlyphListIndex(charCode);
    - if (index < glyphs.size())
    + if (index < glyphs.size() && index != 0)
    kernAdvance += glyphs[index]->Render(penPosition, renderMode);
    }