Al-Qurtas-Islamic-bank-The-.../src
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
..
autofit [autofit] More clean-ups. 2021-07-12 22:11:24 +02:00
base [base] Fix `FT_Open_Face`'s handling of user-supplied streams. 2021-07-13 11:00:48 +02:00
bdf * src/bdf/bdflib.c (_bdf_list_ensure): Tweak allocation macro. 2021-05-07 09:33:41 -04:00
bzip2 [bzip2,gzip] s/FT_ALLOC/FT_QALLOC/ for initialized buffers. 2021-04-23 08:24:22 -04:00
cache Fix compilation errors and (some) warnings for clang++. 2021-05-29 09:51:04 +02:00
cff Fix compilation errors and (some) warnings for clang++. 2021-05-29 09:51:04 +02:00
cid More various documentation improvements and fixes. 2021-06-08 18:23:16 +02:00
dlg Update all copyright notices. 2021-01-17 07:18:48 +01:00
gxvalid [gxvalid,otvalid] s/FT_ALLOC/FT_QALLOC/ for initialized buffers. 2021-04-22 23:07:01 -04:00
gzip [gzip] Use exact type for `ft_gzip_alloc` and `ft_gzip_free`. 2021-05-19 09:07:33 +02:00
lzw [lzw] Preserve decompression stack when relocating to heap. 2021-04-27 11:39:58 -04:00
otvalid [gxvalid,otvalid] s/FT_ALLOC/FT_QALLOC/ for initialized buffers. 2021-04-22 23:07:01 -04:00
pcf [bdf,pcf] Avoid memory zeroing (contd.). 2021-05-02 18:30:22 -04:00
pfr [pfr] Avoid some memory zeroing. 2021-04-26 17:14:28 -04:00
psaux [psaux] Fix another assertion. 2021-06-12 10:13:08 +02:00
pshinter Update all copyright notices. 2021-01-17 07:18:48 +01:00
psnames [sfnt] Additional guards on the POST table. 2021-05-16 23:12:01 -04:00
raster * src/raster/ftraster.c (Render_Single_Pass): Simplify `band_stack'. 2021-06-30 10:54:59 -04:00
sdf [sdf] Improve documentation. 2021-07-13 10:00:22 +02:00
sfnt [sfnt] Support PaintScale in 'COLR' v1 parsing. 2021-07-01 06:49:03 +02:00
smooth [smooth, raster] Fix up and align error codes. 2021-06-24 00:19:50 -04:00
tools Move 'dlg' submodule to `subprojects` directory. 2021-02-16 14:07:18 +01:00
truetype * src/truetype/ttgxvar.c (tt_set_mm_blend): Test `coords`. 2021-07-01 07:02:04 +02:00
type1 [type1] Avoid MM memory zeroing. 2021-05-07 19:17:48 -04:00
type42 Add a comment. 2021-06-15 22:49:21 -04:00
winfonts * src/winfonts/winfnt.c (FNT_Face_Init): Tweak memory macro. 2021-04-26 17:10:28 -04:00