Commit Graph

363 Commits

Author SHA1 Message Date
Alexei Podtelezhnikov 7809007a5b [truetype] Relocate subpixel flag setting.
`TT_RunIns` is too busy to deal with subpixel flags. It is better
to set them in `tt_loader_init`, which is executed before each
glyph program.

* src/truetype/ttinterp.c (TT_RunIns): Move the flag setting from
here...
* src/truetype/ttgload.c (tt_loader_init): ... to here.
2021-12-11 22:22:57 -05:00
Alexei Podtelezhnikov a35b081ebc [truetype] Limit INSTCTRL appication within specs.
* src/truetype/ttinterp.c (Ins_INSTCTRL): Limit its global effects
to the CVT program and local effects to the glyph program.

This also fixes an Infinality buglet. The `ignore_x_mode` should be
locally unset by the glyph program.
2021-12-11 22:12:25 -05:00
Werner Lemberg a11650d7fa * src/truetype/ttinterp.c (Ins_MD): Avoid `FT_ABS`.
Reported as

  https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=38562
2021-11-21 07:54:49 +01:00
Werner Lemberg 0b92c56c34 [truetype] Minor documentation improvements. 2021-10-15 19:02:41 +02:00
Alexei Podtelezhnikov 073ff2d77e [truetype] Clean up `exec` initialization.
* src/truetype/ttinterp.c (Init_Context): Absorbed into...
(TT_New_Context): ... this function.
2021-09-13 00:04:45 -04:00
Alexei Podtelezhnikov fab94f9fcc [truetype] Avoid some memory zeroing.
* src/truetype/ttgload.c (load_truetype_glyph): Use Q-macro.
* src/truetype/ttinterp.c (Update_Max): Ditto.
* src/truetype/ttpload.c (src/truetype/ttpload.c): Ditto.
2021-09-12 23:30:07 -04:00
Werner Lemberg b460a50610 [truetype] Fix integer overflow.
Reported as

  https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=35312

* src/truetype/ttinterp.c (Ins_JMPR): Use `ADD_LONG`.
2021-06-19 07:03:40 +02:00
Alexei Podtelezhnikov 9bfecfd2b6 * src/truetype/ttinterp.c (TT_RunIns): Optimize tracing. 2021-06-09 23:34:04 -04:00
Alexei Podtelezhnikov 56ae943050 [truetype] Avoid some memory zeroing.
* src/truetype/ttinterp.c (Init_Context): Tweak allocation macro.
* src/truetype/ttpload.c (tt_face_load_cvt): Ditto.
2021-05-01 09:14:04 -04:00
Ben Wagner 369d8be97f [truetype] Prevent glyph program state from persisting.
`FDEF` instructions are specified as allowed only in 'prep' or
'fpgm'.  FreeType has attempted to prevent their use in the glyph
program, but they were still allowed in glyph programs if defined in
a function defined in 'prep' or 'fpgm' and called from the glyph
program.

Similarly, `IDEF` instructions are specified not to be able to
modify any existing instruction.  FreeType has attempted to prevent
their use in the glyph program, but they can still be used like
`FDEF`.

This change stores the initial bytecode range type and disallows the
use of `FDEF` and `IDEF` while running the glyph program.

Most other state is copied from the `TT_Size` into the execution
context.  However, it is possible for a glyph program to use `WS` to
write to the storage area or `WCVTP`, `WCVTF`, and `DELTAC[123]` to
write to the control value table.

Allowing any change to the global state from the glyph program is
problematic as the outlines of any given glyph may change based on
the order the glyphs are loaded or even how many times they are
loaded.  There exist fonts that write to the storage area or the
control value table in the glyph program, so their use should not be
an error.

Possible solutions to using these in the glyph program are

  * ignore the writes;
  * value-level copy on write, discard modified values when finished;
  * array-level copy on write, discard the copy when finished;
  * array-level copy up-front.

Ignoring the writes may break otherwise good uses.  A full copy
up-front was implemented, but was quite heavy as even well behaved
fonts required a full copy and the memory management that goes along
with it.  Value-level copy on write could use less memory but
requires a great deal more record keeping and complexity.  This
change implements array-level copy on write.  If any attempt is made
to write to the control value table or the storage area when the
initial bytecode range was in a glyph program, the relevant array
will be copied to a designated storage area and the copy used for
the rest of the glyph program's execution.

* src/truetype/ttinterp.h (TT_ExecContextRec): New fields
`iniRange`, `glyfCvtSize`, `glyfCvt`, `origCvt`, `glyfStoreSize`,
`glyfStorage`, and `origStorage`.

* src/truetype/ttinterp.c (Modify_CVT_Check): New function to handle
`exc->glyfCvt`.
(Write_CVT, Write_CVT_Stretched, Move_CVT, Move_CVT_Stretched): Use
it.
(Ins_WS): Handle `exc->glyfStorage`.
(Ins_FDEF, Ins_IDEF): Updated.
(TT_RunIns): Updated.
(TT_Done_Context): Free 'glyf' CVT working and storage area.
(TT_Load_Context): Fix/add casts.

* src/truetype/ttgload.c (TT_Load_Simple_Glyph): Fix cast.
2021-04-02 10:31:39 +02:00
Werner Lemberg b6e8a71266 Update all copyright notices. 2021-01-17 07:18:48 +01:00
Werner Lemberg c6ff2556c8 [sdf] Use 'counter-clockwise', not 'anti-clockwise'.
We prefer US nomenclature.

* src/sdf/ftsdf.c (SDF_Contour_Orientation):
s/SDF_ORIENTATION-ACW/SDF_ORIENTATION_CCW/.
Update all users.
2020-12-26 10:50:21 +01:00
Werner Lemberg a6adb25626 * src/*: Don't use more than one '\n' in `FT_TRACE` and `FT_ERROR`.
This ensures good logging output, with all lines having a proper
prefix (if requested).
2020-12-05 09:43:45 +01:00
Priyesh Kumar 6d9e6b21e5 * src/*: Fix `-Wformat` warnings. 2020-12-04 16:19:42 +01:00
Alexei Podtelezhnikov 600d59e343 [truetype] Reduce Infinality footprint (cont'd).
* src/truetype/ttinterp.c (Ins_DELTAP): Shrink variable scope.
(Ins_SHPIX, Ins_MIRP): Revise if-logic.
2020-09-02 15:48:03 -04:00
Alexei Podtelezhnikov 51a5e3389c [truetype] Reduce Infinality footprint.
* src/truetype/ttinterp.c (Ins_SHPIX, Ins_MSIRP, Ins_MIAP, Ins_MDRP,
Ins_MIRP): Shrink variable scopes and consolidate ifdefs.
2020-09-02 00:02:28 -04:00
Alexei Podtelezhnikov e6c7e4b42b [truetype] Refactor compensation color.
* src/truetype/ttinterp.h (TT_Round_Func): Change the last argument.
* src/truetype/ttinterp.c (Ins_ROUND, Ins_NROUND, Ins_MDAP, Ins_MIAP,
Ins_MDRP, Ins_MIRP): Move compensation retrieval from here...
(Round_*): ... to here.
* src/truetype/ttobjs.c (tt_size_init_bytecode): Reserve zero
compensation at color index 3.
2020-09-01 21:49:52 -04:00
Priyesh Kumar 53be1753de Fix `-Wformat' compiler warnings.
* src/*: Fix format specifiers.

* builds/unix/ftsystem.c (FT_Stream_Open): Ditto.
2020-07-28 07:33:40 +02:00
Werner Lemberg 96fb73efd5 Fix clang warnings.
* include/freetype/internal/autohint.h
(FT_DECLARE_AUTOHINTER_INTERFACE): New macro.
* src/autofit/afmodule.h: Use it to declare
`af_autofitter_interface'.

* include/freetype/internal/ftobjs.h (FT_DECLARE_GLYPH): New macro.
* src/base/ftbase.h: Use it to declare `ft_bitmap_glyph_class' and
`ft_outline_glyph_class'.

* src/base/ftglyph.c: Include `ftbase.h'.

* src/cff/cffparse.c (cff_parser_run): Fix type of `t2_size'.

* src/pcf/pcfdrivr.c (pcf_cmap_char_next): Fix type of `result'.

* src/psaux/psauxmod.c (psaux_module_class): Use `FT_DEFINE_MODULE'.
* src/psaux/psauxmod.h: Declare `afm_parser_funcs',
`t1_cmap_classes', `cff_decoder_funcs', and `psaux_module_class'.

* src/pshinter/pshmod.c: Include `pshmod.h'.

* src/sfnt/sfwoff2.c (ROUND4, WRITE_SHORT): Fix implicit sign
conversion.
(compute_ULong_sum): Fix return type.
Fix implicit sign conversion.
(store_points): Fix type of `last_flag', `repeat_count', and `flag'.
Use casts to avoid warnings.
(reconstruct_glyf): Fix implicit sign conversion.
Use cast to avoid warning.
(get_x_mins): Fix implicit sign conversion.
* src/sfnt/ttcmap.c: Undef `TTCMAPCITEM'.
* src/sfnt/ttcmap.h: Define `TTCMAPCITEM' and include `ttcmapc.h' to
declare cmap classes.

* src/smooth/ftsmooth.c (ft_smooth_overlap_spans): Use cast.

* src/truetype/ttinterp.c (Ins_MIAP): Fix typo.
2020-07-07 16:58:14 +02:00
Werner Lemberg 1658685967 Remove redundant inclusion of `ft2build.h'.
* */*: Remove `#include <ft2build.h>' where possible.

* include/freetype/freetype.h: Remove cpp error about missing
inclusion of `ft2build.h'.
2020-06-13 21:15:45 +02:00
David Turner e13391333f Make macros for header file names optional.
We no longer have to take care of the 8.3 file name limit; this
allows us (a) to introduce longer, meaningful file names, and (b) to
avoid macro names in `#include' lines altogether since some
compilers (most notably Visual C++) doesn't support this properly.

*/*: Replace

   #include FOO_H

with

   #include <freetype/foo.h>

or something similar.  Also update the documentation.
2020-06-08 13:31:55 +02:00
Jakub Alba a45da25349 * src/truetype/ttinterp.c (TT_RunIns): Adjust loop counter (#58319).
The font that exceeds the old limit is Icono Regular, version
1.00000.
2020-05-08 10:59:37 +02:00
Werner Lemberg 4a19a53d5a * src/truetype/ttinterp.c (TT_RunIns): Adjust loop counter (#57732).
The font that exceeds the old limit is Constantine, version 1.001.
2020-02-04 13:37:19 +01:00
Werner Lemberg e5038be704 Update all copyright notices. 2020-01-19 17:05:19 +01:00
Dominik Röttsches 10d8de7541 [truetype] Fix UBSan warning on offset to nullptr (#57501).
* src/truetype/ttinterp.c (Ins_CALL): Fail if `exc->FDefs' is null.
2020-01-02 11:14:01 +01:00
Dominik Röttsches 8cee1dde4e Fix more UBSan warnings on adding offset to nullptr (#57432).
* src/truetype/ttinterp.c (Ins_LOOPCALL), src/psaux/psft.c
(cf2_initLocalRegionBuffer): Use `FT_OFFSET'.
2019-12-21 19:03:48 +01:00
Werner Lemberg 7e1b39f6cd [truetype] Fix UBSan warnings on adding offsets to nullptr.
Reported as

  https://bugs.chromium.org/p/chromium/issues/detail?id=1032152

* src/truetype/ttinterp.c (Ins_FDEF, Ins_IDEF): Use `FT_OFFSET'.
2019-12-16 11:07:58 +01:00
Werner Lemberg 0c14a3adb0 [truetype] Fix integer overflow.
Reported as

  https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=19305

* src/truetype/ttinterp.c (Ins_MIRP): Use `ADD_LONG'.
2019-12-14 00:04:01 +01:00
Werner Lemberg dfc9a049de * src/truetype/ttinterp.c (TT_RunIns): Use `FT_OFFSET'.
Reported as

  https://bugs.chromium.org/p/chromium/issues/detail?id=1030614
2019-12-05 08:44:30 +01:00
Werner Lemberg 551bd3a90e More nullptr offset UBSan warnings (#57331, #57347).
* src/autofit/afcjk.c (af_cjk_hints_compute_segments),
src/psaux/psft.c (cf2_getSeacComponent), src/truetype/ttinterp.c
(Ins_UNKNOWN): Use `FT_OFFSET'.
2019-12-03 11:52:48 +01:00
Werner Lemberg c3be6f06b7 src/truetype/ttinterp.c: Give order of operations for some instructions. 2019-05-21 11:23:36 +02:00
Werner Lemberg 262fce445a * src/truetype/ttinterp.c (opcode_name): Improve mnemonics. 2019-05-21 09:58:51 +02:00
Werner Lemberg 7585997024 Update all copyright notices. 2019-02-23 10:07:09 +01:00
Armin Hasitzka b77826e139 Triage 8ea854bfe9. 2019-02-21 10:23:15 +00:00
Armin Hasitzka 8ea854bfe9 [truetype] Mask numeric overflows.
* src/truetype/ttinterp.c (Move_CVT, Move_CVT_Stretched, Ins_MIRP):
Mask numeric overflows.

Reported as

  https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=11681
  https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=11734
2019-02-21 10:14:57 +00:00
Werner Lemberg f686ad46a3 Update copyright years. 2019-01-22 20:31:44 +01:00
Werner Lemberg 2b4e61e4d6 Minor documentation fixes. 2018-12-12 09:36:39 +01:00
Werner Lemberg a0dd16fb3d Don't use `trace_' prefix for FT_COMPONENT arguments.
* include/freetype/internal/ftdebug.h (FT_TRACE_COMP,
FT_TRACE_COMP_): New auxiliary macros to add `trace_' prefix.
(FT_TRACE): Use `FT_TRACE_COMP'.

*/* (FT_COMPONENT): Updated.
2018-08-15 18:13:17 +02:00
Werner Lemberg 1d7b034cd8 Use formatting string in FT_TRACEX calls for non-simple arguments.
* src/psaux/cffdecode.c (cff_decoder_parse_charstrings)
<cff_op_hstem, cff_op_hintmask, cff_op_hlineto, cff_op_vhcurveto>:
Do it.

* src/psaux/pshints.c (cf2_hintmap_build): Ditto.

* src/psaux/psintrp.c (cf2_interpT2CharString) <cf2_cmdHSTEM,
cf2_cmdVSTEM, cf2_cmdHLINETO, cf2_cmdRRCURVETO, cf2_cmdCALLSUBR,
cf2_escHSTEM3, cf2_cmdHINTMASK, cf2_cmdHVCURVETO>: Ditto.

* src/truetype/ttinterp.c (TT_RunIns): Ditto.
2018-08-14 15:56:28 +02:00
Werner Lemberg ced9c311f6 Ditto. 2018-08-04 07:03:57 +02:00
Werner Lemberg be81acc4bf * src/truetype/ttinterp.c (opcode_name): Fix typos. 2018-08-04 07:01:04 +02:00
Hin-Tak Leung 71e29fe1c9 [truetype] Match ttdebug's naming of instruction mnemonics.
* src/truetype/ttinterp.c: The form used in ttdebug,
"MDRP[G,B,W,?]", etc., is slightly more readable than
"MDRP[00,01,02,03]".
2018-07-24 10:04:23 +02:00
Nikhil Ramakrishnan 78d85b9c84 Restore missing comment lines and other minor fixes 2018-06-04 20:33:56 +05:30
Werner Lemberg 9ac9060df0 [GSoC] src/*.*: Convert block comments to `light' style.
This monster commit was created by applying Nikhil's scripts
`docconverter.py' and `markify.py' to all C header and source files,
followed up by minor manual clean-up.

No change in functionality, of course.

I used commit f7419907bc6044b9b7057f9789866426c804ba82 from
https://github.com/nikramakrishnan/freetype-docs.git.
2018-06-03 09:08:41 +02:00
Werner Lemberg 67994e8221 * src/truetype/ttinterp.c (Ins_MIRP): Use SUB_LONG; avoid FT_ABS.
Reported as

  https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=8706
2018-06-02 19:51:03 +02:00
Werner Lemberg 2a1597826a [truetype] Integer overflow issues.
Reported as

  https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=7739

* src/truetype/ttinterp.c (Ins_CEILING): Use FT_PIX_CEIL_LONG.
2018-04-17 12:25:17 +02:00
Werner Lemberg 70ac167c47 [truetype] Integer overflow issues.
Reported as

  https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=7718

* src/truetype/ttinterp.c (Ins_MIRP): Use ADD_LONG.
2018-04-16 10:39:10 +02:00
Werner Lemberg 235b1e2fe6 [truetype]: Limit `SLOOP' bytecode argument to 16 bits.
This fixes

  https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=7707

* src/truetype/ttinterp.c (Ins_SLOOP): Do it.
2018-04-15 21:55:04 +02:00
Werner Lemberg 827ca3bcf2 [truetype] Integer overflow issues.
Reported as

  https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=7652

* src/truetype/ttinterp.c (Ins_MDAP): Use SUB_LONG.
2018-04-14 07:20:31 +02:00
Werner Lemberg bd9400bd46 [truetype] Integer overflow issues.
Reported as

  https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=7453

* src/truetype/ttinterp.c (Round_Super, Round_Super_45): Use
ADD_LONG and SUB_LONG.
2018-04-09 21:28:37 +02:00