We are currently migrating Bugzilla to GitHub issues.
Any changes made to the bug tracker now will be lost, so please do not post new bugs or make changes to them.
When we're done, all bug URLs will redirect to their equivalent location on the new bug tracker.

Bug 2692

Summary: TTF_Render*_Shaded invalid read
Product: SDL_ttf Reporter: Joshua Landau <joshua>
Component: miscAssignee: Sam Lantinga <slouken>
Status: RESOLVED FIXED QA Contact: Sam Lantinga <slouken>
Severity: normal    
Priority: P2    
Version: 2.0.12   
Hardware: x86_64   
OS: Linux   

Description Joshua Landau 2014-08-18 20:45:26 UTC
When using the Hans Kendrick font with SDL2_ttf;

    #include <stdio.h>
    #include <SDL2/SDL.h>
    #include <SDL2/SDL_ttf.h>

    // Very shortened for demo purposes
    int main () {
        if (SDL_Init(SDL_INIT_VIDEO) != 0) { return 1; }
        if (TTF_Init() == -1) { return 1; }

        TTF_Font *font = TTF_OpenFont("font.ttf", 28);

        if (font == NULL) { return 1; }

        SDL_Color blank = {0, 0, 0, 0};
        SDL_Color colour = {0, 0, 0, 0};

        TTF_RenderUTF8_Shaded(font, "Y", colour, blank);
    }

valgrind reports an error;

    ==18109== Invalid read of size 1
    ==18109==    at 0x535812C: TTF_RenderUTF8_Shaded (in /usr/lib/libSDL2_ttf-2.0.so.0.10.2)
    ==18109==    by 0x40080B: main (in /home/joshua/fontbug/test)
    ==18109==  Address 0xd9aaf4f is 1 bytes before a block of size 560 alloc'd
    ==18109==    at 0x4C28730: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
    ==18109==    by 0x4ED91FB: ??? (in /usr/lib/libSDL2-2.0.so.0.2.1)
    ==18109==    by 0x5357F00: TTF_RenderUTF8_Shaded (in /usr/lib/libSDL2_ttf-2.0.so.0.10.2)
    ==18109==    by 0x40080B: main (in /home/joshua/fontbug/test)

and some systems crash. This depends on the characters (strings with a space at the front have never had this problem) and possibly the font size.

---

This is pretty much copied verbatim from my Stack Overflow post on the same issue:

http://stackoverflow.com/questions/25369043/ttf-renderutf8-shaded-invalid-read?noredirect=1#comment39563751_25369043
Comment 1 Sam Lantinga 2014-08-20 04:21:53 UTC
Thanks for the bug report. If the font is freely available, can you post a link to it, or attach it to this bug?

Can you rebuild SDL_ttf with debug symbols so you can get line number information?

Does it happen with the latest version from Mercurial?
Comment 2 Joshua Landau 2014-09-05 07:22:36 UTC
This doesn't happen with the latest SDL2_ttf from Mercurial and I no longer need a solution, so I doubt much needs following up on.

I guess I'll probably revisit this in a year or so to check.

FWIW, the font is available here:
http://openfontlibrary.org/en/font/hans-kendrick
Comment 3 Sam Lantinga 2017-09-10 06:03:29 UTC
It sounds like this has been fixed.

Thanks!