Werner Lemberg pushed to branch master at FreeType / FreeType
Commits:
-
06e21ffe
by Ben Wagner at 2021-05-19T09:07:33+02:00
2 changed files:
Changes:
1 |
+2021-05-19 Ben Wagner <bungeman@chromium.org>
|
|
2 |
+ |
|
3 |
+ [gzip] Use exact type for `ft_gzip_alloc` and `ft_gzip_free`.
|
|
4 |
+ |
|
5 |
+ While a function pointer may be cast to another function pointer
|
|
6 |
+ type, it is required to cast the function pointer back to the
|
|
7 |
+ original function pointer type before calling it. If a parameter is
|
|
8 |
+ a pointer the exact pointer type is required. Using a pointer to a
|
|
9 |
+ different underlying type is technically undefined behavior. The
|
|
10 |
+ wrapper functions `ft_gzip_alloc` and `ft_gzip_free` took
|
|
11 |
+ `FT_Memory` (a `FT_MemoryRec_*`) instead of `voidpf` (`void*`), so
|
|
12 |
+ when gzip calls these callbacks through `alloc_func` or `free_func`
|
|
13 |
+ it invokes undefined behavior. On most platforms this works out as
|
|
14 |
+ expected, but newer undefined behavior detectors and targets like
|
|
15 |
+ wasm can detect this and will produce an error.
|
|
16 |
+ |
|
17 |
+ * src/gzip/ftgzip.c (ft_gzip_alloc, ft_gzip_free): Update signatures
|
|
18 |
+ to exactly match `alloc_func` and `free_func`, respectively.
|
|
19 |
+ Internally, cast the `void*` opaque pointer to `FT_Memory`.
|
|
20 |
+ |
|
1 | 21 |
2021-05-18 Alexei Podtelezhnikov <apodtele@gmail.com>
|
2 | 22 |
|
3 | 23 |
Prioritize the anti-aliasing renderer module.
|
... | ... | @@ -121,13 +121,14 @@ |
121 | 121 |
'malloc/free' */
|
122 | 122 |
|
123 | 123 |
static voidpf
|
124 |
- ft_gzip_alloc( FT_Memory memory,
|
|
125 |
- uInt items,
|
|
126 |
- uInt size )
|
|
124 |
+ ft_gzip_alloc( voidpf opaque,
|
|
125 |
+ uInt items,
|
|
126 |
+ uInt size )
|
|
127 | 127 |
{
|
128 |
- FT_ULong sz = (FT_ULong)size * items;
|
|
128 |
+ FT_Memory memory = (FT_Memory)opaque;
|
|
129 |
+ FT_ULong sz = (FT_ULong)size * items;
|
|
129 | 130 |
FT_Error error;
|
130 |
- FT_Pointer p = NULL;
|
|
131 |
+ FT_Pointer p = NULL;
|
|
131 | 132 |
|
132 | 133 |
|
133 | 134 |
/* allocate and zero out */
|
... | ... | @@ -137,9 +138,12 @@ |
137 | 138 |
|
138 | 139 |
|
139 | 140 |
static void
|
140 |
- ft_gzip_free( FT_Memory memory,
|
|
141 |
- voidpf address )
|
|
141 |
+ ft_gzip_free( voidpf opaque,
|
|
142 |
+ voidpf address )
|
|
142 | 143 |
{
|
144 |
+ FT_Memory memory = (FT_Memory)opaque;
|
|
145 |
+ |
|
146 |
+ |
|
143 | 147 |
FT_MEM_FREE( address );
|
144 | 148 |
}
|
145 | 149 |
|
... | ... | @@ -151,14 +155,14 @@ |
151 | 155 |
unsigned items,
|
152 | 156 |
unsigned size )
|
153 | 157 |
{
|
154 |
- return ft_gzip_alloc( (FT_Memory)opaque, items, size );
|
|
158 |
+ return ft_gzip_alloc( opaque, items, size );
|
|
155 | 159 |
}
|
156 | 160 |
|
157 | 161 |
local void
|
158 | 162 |
zcfree( voidpf opaque,
|
159 | 163 |
voidpf ptr )
|
160 | 164 |
{
|
161 |
- ft_gzip_free( (FT_Memory)opaque, ptr );
|
|
165 |
+ ft_gzip_free( opaque, ptr );
|
|
162 | 166 |
}
|
163 | 167 |
|
164 | 168 |
#endif /* !SYSTEM_ZLIB && !USE_ZLIB_ZCALLOC */
|
... | ... | @@ -305,8 +309,8 @@ |
305 | 309 |
}
|
306 | 310 |
|
307 | 311 |
/* initialize zlib -- there is no zlib header in the compressed stream */
|
308 |
- zstream->zalloc = (alloc_func)ft_gzip_alloc;
|
|
309 |
- zstream->zfree = (free_func) ft_gzip_free;
|
|
312 |
+ zstream->zalloc = ft_gzip_alloc;
|
|
313 |
+ zstream->zfree = ft_gzip_free;
|
|
310 | 314 |
zstream->opaque = stream->memory;
|
311 | 315 |
|
312 | 316 |
zstream->avail_in = 0;
|
... | ... | @@ -742,8 +746,8 @@ |
742 | 746 |
stream.next_out = output;
|
743 | 747 |
stream.avail_out = (uInt)*output_len;
|
744 | 748 |
|
745 |
- stream.zalloc = (alloc_func)ft_gzip_alloc;
|
|
746 |
- stream.zfree = (free_func) ft_gzip_free;
|
|
749 |
+ stream.zalloc = ft_gzip_alloc;
|
|
750 |
+ stream.zfree = ft_gzip_free;
|
|
747 | 751 |
stream.opaque = memory;
|
748 | 752 |
|
749 | 753 |
/* This is a temporary fix and will be removed once the internal
|