freetype2/src/base
Oleg Oshmyan 5d27b10f4c [base] Fix `FT_Open_Face`'s handling of user-supplied streams.
This was already true (though undocumented) most of the time, but
not if `FT_NEW` inside `FT_Stream_New` failed or if the
`FT_OPEN_XXX` flags were bad.

Normally, `FT_Open_Face` calls `FT_Stream_New`, which returns the
user-supplied stream unchanged, and in case of any subsequent error
in `FT_Open_Face`, the stream is closed via `FT_Stream_Free`.

Up to now, however, `FT_Stream_New` allocates a new stream even if
it is already given one by the user.  If this allocation fails, the
user-supplied stream is not returned to `FT_Open_Face` and never
closed.  Moreover, the user cannot detect this situation: all they
see is that `FT_Open_Face` returns `FT_Err_Out_Of_Memory`, but that
can also happen after a different allocation fails within the main
body of `FT_Open_Face`, when the user's stream has already been
closed by `FT_Open_Face`.  It is plausible that the user stream's
`close` method frees memory allocated for the stream object itself,
so the user cannot defensively free it upon `FT_Open_Face` failure
lest it ends up doubly freed.  All in all, this ends up leaking the
memory/resources used by user's stream.

Furthermore, `FT_Stream_New` simply returns an error if the
`FT_OPEN_XXX` flags are unsupported, which can mean either an
invalid combination of flags or a perfectly innocent
`FT_OPEN_STREAM` on a FreeType build that lacks stream support.
With this patch, the user-supplied stream is closed even in these
cases, so the user can be sure that if `FT_Open_Face` failed, the
stream is definitely closed.

* src/base/ftobjs.c (FT_Stream_New): Don't allocate a buffer
unnecessarily.
Move error-handling code to make the control flow more obvious.
Close user-supplied stream if the flags are unsupported.
`FT_Stream_Open` always sets `pathname.pointer`, so remove the
redundant (re)assignment.  None of the `FT_Stream_Open...` functions
uses `stream->memory`, so keep just one assignment at the end,
shared among all possible control flow paths.
('Unsupported flags' that may need a stream closure can be either an
invalid combination of multiple `FT_OPEN_XXX` mode flags or a clean
`FT_OPEN_STREAM` flag on a FreeType build that lacks stream
support.)
2021-07-13 11:00:48 +02:00
..
ftadvanc.c Update all copyright notices. 2021-01-17 07:18:48 +01:00
ftbase.c Update all copyright notices. 2021-01-17 07:18:48 +01:00
ftbase.h Update all copyright notices. 2021-01-17 07:18:48 +01:00
ftbbox.c Update all copyright notices. 2021-01-17 07:18:48 +01:00
ftbdf.c Update all copyright notices. 2021-01-17 07:18:48 +01:00
ftbitmap.c Update all copyright notices. 2021-01-17 07:18:48 +01:00
ftcalc.c More various documentation improvements and fixes. 2021-06-08 18:23:16 +02:00
ftcid.c Update all copyright notices. 2021-01-17 07:18:48 +01:00
ftcolor.c Update all copyright notices. 2021-01-17 07:18:48 +01:00
ftdbgmem.c Update all copyright notices. 2021-01-17 07:18:48 +01:00
ftdebug.c Always provide logging API. 2021-01-31 14:28:44 +01:00
fterrors.c Update all copyright notices. 2021-01-17 07:18:48 +01:00
ftfntfmt.c Update all copyright notices. 2021-01-17 07:18:48 +01:00
ftfstype.c Update all copyright notices. 2021-01-17 07:18:48 +01:00
ftgasp.c Update all copyright notices. 2021-01-17 07:18:48 +01:00
ftgloadr.c Update all copyright notices. 2021-01-17 07:18:48 +01:00
ftglyph.c Update all copyright notices. 2021-01-17 07:18:48 +01:00
ftgxval.c Update all copyright notices. 2021-01-17 07:18:48 +01:00
fthash.c Remove redundant inclusion of `ft2build.h'. 2020-06-13 21:15:45 +02:00
ftinit.c Update all copyright notices. 2021-01-17 07:18:48 +01:00
ftlcdfil.c * src/base/ftlcdfil.c (FT_Library_SetLcdGeometry): Fix argument. 2021-07-05 05:41:53 +02:00
ftmac.c [base] s/FT_ALLOC/FT_QALLOC/ for initialized buffers. 2021-04-22 22:34:05 -04:00
ftmm.c Update all copyright notices. 2021-01-17 07:18:48 +01:00
ftobjs.c [base] Fix `FT_Open_Face`'s handling of user-supplied streams. 2021-07-13 11:00:48 +02:00
ftotval.c Update all copyright notices. 2021-01-17 07:18:48 +01:00
ftoutln.c Update all copyright notices. 2021-01-17 07:18:48 +01:00
ftpatent.c Update all copyright notices. 2021-01-17 07:18:48 +01:00
ftpfr.c Update all copyright notices. 2021-01-17 07:18:48 +01:00
ftpsprop.c Update all copyright notices. 2021-01-17 07:18:48 +01:00
ftrfork.c * src/base/ftrfork.c (FT_Raccess_Get_DataOffsets): Tweak allocation. 2021-05-06 22:49:13 -04:00
ftsnames.c [base] Avoid some memory zeroing. 2021-04-25 23:40:59 -04:00
ftstream.c Update all copyright notices. 2021-01-17 07:18:48 +01:00
ftstroke.c Handle various VC++ compiler warnings. 2021-03-13 19:08:09 +01:00
ftsynth.c Update all copyright notices. 2021-01-17 07:18:48 +01:00
ftsystem.c Update all copyright notices. 2021-01-17 07:18:48 +01:00
fttrigon.c Update all copyright notices. 2021-01-17 07:18:48 +01:00
fttype1.c Update all copyright notices. 2021-01-17 07:18:48 +01:00
ftutil.c Update all copyright notices. 2021-01-17 07:18:48 +01:00
ftver.rc ftver.rc: Update copyright year. 2021-06-19 15:45:46 +02:00
ftwinfnt.c Update all copyright notices. 2021-01-17 07:18:48 +01:00
md5.c * src/base/md5.c: Updated to recent version. 2016-06-16 06:17:54 +02:00
md5.h * src/base/md5.c, src/base/md5.h: Updated to recent version. 2013-10-22 01:10:10 +02:00
rules.mk Update all copyright notices. 2021-01-17 07:18:48 +01:00