Fri 09 Oct 2009 02:56:37 PM UTC, original submission:
There is no way to properly initialize 'raster' field of the custom renderers for glyph formats except FT_GLYPH_FORMAT_OUTLINE.
If this field is not initialized at least with NULL, it may lead to memory access violation when trying to release the library. FT_Done_Freetype eventually calls ft_remove_renderer(). Consider the following lines of this function (ftobjs.c from git repository, line 3682):
/* release raster object, if any */
if ( render->raster )
render->clazz->raster_class->raster_done( render->raster );
As far as I can see from Freetype reference, 'raster_class' is intended to use for FT_GLYPH_FORMAT_OUTLINE renderers only. As for the renderers for other formats, this field should probably be set to NULL.
So, as render->raster is not initialized and may contain some non-NULL garbage, the lines above will result in NULL pointer dereference. Even if 'render->clazz->raster_class' is not NULL and provides 'raster_done' method, the latter will be called with an invalid pointer - access violation again.
The definition of FT_RendererRec_ structure is private and hence 'raster' field is not accessible directly (and it probably should not be).
Initialization of render->raster via raster_new() is available only for FT_GLYPH_FORMAT_OUTLINE format, so this too cannot be used as a workaround.
If 'raster' field was automatically set to NULL somehow when a non-FT_GLYPH_FORMAT_OUTLINE renderer is created, it would solve the problem. Or maybe there are other solutions.
[NB] It should also be mentioned that the description of FT_Renderer_Class_ states that the structure must also contain 'raster' field. The structure itself however has in fact all the described fields except for 'raster' (ftrender.h).
Probably the structure should not contain this field at all and it got into the description by mistake. After all, as far as I can see, only 'raster' field of FT_Renderer_Rec_ is used by Freetype library, rather than that field of FT_Renderer_Class_ structures.
Not sure if the issues described above are related.
|