* src/sfnt/ttpost.c (load_format_20): Co-allocate the string data and
their pointers, which makes it easier to handle and free them.
(tt_face_free_ps_names): Updated.
* include/freetype/internal/tttypes.h (TT_Post_20): Update type.
* src/cff/cffparse.c (cff_parser_run): Allocate the charstring buffers
and the list nodes together so that they can be freed at once.
(finalize_t2_strings): Removed as no longer needed.
(cff_parser_done): Updated.
The old stream limit checks, before 6986ddac1e, were good but
pointless for the crafted t2_strings. Checking limits there is
not necessary as they are created to hold all data. By using two
conditions, we can detect the actual crossing of the stream boundary
as appropriate for the stream pointer only. The t2_strings parsing
will not be triggering these checks.
* src/cff/cffparse.c (cff_parser_within_limits): Removed.
(cff_parse_real, cff_parse_integer): Redesign the stream limit check.
(cff_parse_num, do fixed, cff_parse_fixed_dynamic): Update callers.
The problem occured when unpacking a zip file created on OpenVMS on Linux.
While OpenVMS knows many different file formats, Unix only knows stream-LF
and binary. In principle `zip` on Linux should have translated the file to
stream-LF but failed to do so. That caused the file to incorrectly contain
only one line with control-characters.
* src/truetype/ttgload.c (TT_Process_Composite_Glyph,
TT_Load_Simple_Glyph): Clean up old instructions regardless of
new ones, postpone setting `control_len` and `control_data` until...
(TT_Load_Glyph): ... the exit from this function.
The number of instructions is now taken from the executed context.
Technically, this means that `control_len` and `control_data`
values are no longer _used_ internally but only expose them.
Based on ideas from Jouk Jansen <joukj@hrem.nano.tudelft.nl>.
* src/tools/vms_shorten_symbol.c: New file, taken from
https://sourceforge.net/p/vms-ports/vmsshortsym/ci/default/tree/vms_shorten_symbol.c
with some minor edits to allow compilation with C++ and being included in
another source code file.
* src/tools/apinames.c: Include `vms_shorten_symbol.c`.
(PROGRAM_VERSION): Set to '0.5'.
(names_dump) [OUTPUT_VMS_OPT]: Call `vms_shorten_symbol` to get unique function
identifiers not longer than 31 characters.
* src/cff/cffparse.c (finalize_t2_strings): Fix NULL-dereferencing
in the out-of-memory situation, use `FT_FREE`.
(cff_parser_run): Use FreeType memory allocation macros and avoid
uninitialized pointers.
Technically, `strtol` can only be used with C strings terminated with
`\0`. CID data is not generally null-terminated and often does not
contain a `\0` if it is hex-encoded. AddressSanitizer with `ASAN_OPTIONS`
containing `strict_string_checks=1` verifies this by using an adversarial
`strtol` that always reads to the terminating `\0`.
To avoid undefined behavior from `strtol` in `cid_parser_new`, use the
parser to parse the tokens instead of attempting to parse them ad-hoc.
This will internally use `PS_Conv_Strtol` to parse the integer, which
respects the parser's limits and directly implements the PostScript
parsing rules for integers.
* src/cid/cidparse.c (cid_parser_new): Use the parser to parse the
tokens.
Fixes: https://bugs.chromium.org/p/chromium/issues/detail?id=1420329
Without this patch, static linking with MS Visual Studio causes linking
errors.
* src/gzip/ftgzip.c: Set `ZEXPORT` to nothing and `ZEXTERN` to static for
all compilers.
TeXLive still supports Solaris 5.10, where the system's `grep` doesn't
accept the `-E` option. We thus introduce an `EGREP` variable that is set
to either `grep -E` or `-egrep`.
This is unnecessary for predefined standard and expert encodings.
Even for custom encodings the arrays might be already zeroed when
CFF_FontRec is created but we keep it just in case.
Also short-circuit on `offset` to avoid checking `count` a second time when
`ft_ansi_stream_io` is used for reading.
Per ISO/IEC 9899:
If an argument to a function has an invalid value (such as a value outside
the domain of the function, or a pointer outside the address space of the
program, or a null pointer, or apointer to non-modifiable storage when the
corresponding parameter is not const-qualified) or a type (after
promotion) not expected by a function with variable number of arguments,
the behavior is undefined. If a function argument is described as being
an array, the pointer actually passed to the function shall have a value
such that all address computations and accesses to objects (that would be
valid if the pointer did point to the first element of such an array) are
in fact valid.
Per IEEE Std 1003.1:
size_t fread(void *restrict ptr, size_t size, size_t nitems,
FILE *restrict stream);
The `fread` function shall read into the array pointed to by `ptr` up to
`nitems` elements whose size is specified by `size` in bytes, from the
stream pointed to by `stream`.
Since the first argument to `fread` is described as being an array, its
behavior is undefined when that argument is a null pointer.
Per the documentation on `ft_ansi_stream_io`:
If `count' is zero (this is, the function is used for seeking), a non-zero
return value indicates an error.
Thus the intent is clear, and the call to `fread` can be skipped, avoiding
undefined behaviour.