win32: Fix regression with text containing space character

Converting a series of glyphs to a path triggers an out of memory error
if there is a space glyph (bytesGlyph==0).  The regression was
introduced by commit 19982393 in cairo-win32-font.c:107.

The behavior of malloc(0) is not well defined - it can return NULL on
some platforms, or an arbitrary (non-allocated) pointer on other
platforms.  Commit 19982393 introduced sanity by enforcing that NULL is
always returned in this situation, which inappropriately triggers the
OOM check in _cairo_win32_scaled_font_init_glyph_path().  Instead,
special case the handling for bytesGlyph==0.

Patch authored by Uli Schlachter, based on fix proposed by lb90.

Fixes:  https://gitlab.freedesktop.org/cairo/cairo/issues/339
Reference:  https://gitlab.gnome.org/GNOME/pango/issues/323
Reviewed-by: Bryce Harrington <bryce@bryceharrington.org>
This commit is contained in:
Bryce Harrington 2018-10-17 17:32:10 -07:00
parent 7786b8fe4e
commit 3a03c1ba4b

View file

@ -1697,7 +1697,7 @@ _cairo_win32_scaled_font_init_glyph_path (cairo_win32_scaled_font_t *scaled_font
}
ptr = buffer = _cairo_malloc (bytesGlyph);
if (!buffer) {
if (!buffer && bytesGlyph != 0) {
status = _cairo_error (CAIRO_STATUS_NO_MEMORY);
goto CLEANUP_FONT;
}