8693 Commits
Author SHA1 Message Date
John Tytgat f80f688894 [cff] Fix handling of horiAdvance and vertAdvance.
* src/cff/cffgload.c (cff_slot_load): The `horiAdvance` value needs
  an adjustment for a non-uniform scaling matrix when it came from a raw CFF
  data blob but not for the OpenType/CFF case when an 'hmtx' table is
  available.  Similarly, the `vertAdvance` value does never come from the
  CFF data blob so it doesn't need adjustment.
2026-11-30 08:35:04 +01:00
John Tytgat 7ecef80230 [cff] Avoid unnecessary assignment of horiBearingX.
* src/cff/cffgload.c (cff_slot_load): When there is an 'hmtx' table
available, don't use its `horiBearingX` information as that gets
unconditionally overruled based on the result of `FT_Outline_Get_CBox` later
on.
2026-11-30 08:35:04 +01:00
John Tytgat 14511d4718 [cff, cid, type1] Fix glyph metrics advance.
* src/cff/cffgload.c (cff_slot_load): Don't adjust
  `FT_GlyphMetrics::{horiAdvance,vertAdvance}` for non-zero font matrix
  offsets as these are vectors, not points.
* src/cid/cidgload.c (cid_slot_load_glyph): Likewise.
* src/cid/type1/t1gload.c (T1_Load_Glyph): Likewise.
2026-11-30 08:34:28 +01:00
John Tytgat 68db2bb4a4 2026-11-22 John Tytgat <John.Tytgat@esko.com>
* src/type1/t1gload.c (T1_Get_Advances): Take non-uniform font matrix
	xx vs yy scaling into account.
	(T1_Load_Glyph) [linearHoriAdvance]: Likewise.
	* src/cid/cidgload.c (cid_slot_load_glyph) [linearHoriAdvance]: Likewise.
	* src/cff/cffgload.c (cff_slot_load) [linearHoriAdvance]: Likewise.
	Including different top/sub font units_per_em values.
2026-11-25 10:23:32 +00:00
Alexei Podtelezhnikov d4d00b890a Remove comment. 2026-11-23 18:55:32 -05:00
Alexei Podtelezhnikov a295e1c6eb * src/truetype/ttgxvar.c (tt_var_load_item_variation_store): Clarify.
The overfow is only possible when both int and long have the same size.
2026-11-23 17:16:12 -05:00
Alexei Podtelezhnikov 6b9f170a2c * src/base/ftbbox.c (cubic_peak): Assure non-negative outcome.
This is an alternative fix to #1489.
2026-11-23 17:09:00 -05:00
Behdad Esfahbod (بهداد اسفهبد)andClaude Fable 5.2 504159f273 * src/truetype/ttgxvar.c (ft_var_load_gvar): Fix memory leak.
If the allocation of `tuplescalars` fails, `tuplecoords` was left in
place, to be overwritten and leaked by the next call.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-22 12:49:12 +00:00
Behdad Esfahbod (بهداد اسفهبد)andClaude Fable 5.2 99aa453032 * src/base/fthash.c: Handle allocation failures.
(hash_rehash): If the new table cannot be allocated, keep the old one
instead of leaking it and leaving `hash->table` at `NULL`.
(hash_insert): Undo the insertion if the table cannot grow.
(ft_hash_str_free): Handle a hash whose table `hash_init` could not
allocate.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-22 12:49:12 +00:00
Behdad Esfahbod (بهداد اسفهبد)andClaude Fable 5.2 0de64f46c0 [sfnt, psaux] Handle a missing MM service.
The `cff` module takes its MM service from the `truetype` module.  If
the library has no such module, `face->mm` is `NULL`, yet a CFF2 font
with an `fvar` table was still flagged as a variation font, and
`cff_set_named_instance` crashed while opening it.

To reproduce, remove the `truetype` module with `FT_Remove_Module` and
open a CFF2 variation font.  Such a font now opens at its default
instance.

* src/sfnt/sfobjs.c (sfnt_init_face): Ignore `fvar` without the MM
service.

* src/psaux/psft.c (cf2_getNormalizedVector): Return an empty vector
without the MM service.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-22 12:49:12 +00:00
Behdad Esfahbod (بهداد اسفهبد)andClaude Fable 5.2 f293db217b [autofit] Handle a missing reverse character map.
If `af_reverse_character_map_new` fails, the map is `NULL`.  This
happens if there is no Unicode charmap, or if memory is exhausted.  The
lookups in the Latin hinter passed it on to `ft_hash_num_lookup`, which
dereferences it.

To reproduce, set the `fallback-script` property to Latin and load a
glyph of a font without a Unicode charmap with `FT_LOAD_FORCE_AUTOHINT`.

* src/autofit/aflatin.c
(af_glyph_hints_apply_vertical_separation_adjustments,
af_latin_hints_apply): Check `reverse_charmap`.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-22 12:49:12 +00:00
Werner Lemberg 4fc22c56fc * src/base/ftbbox.c (cubic_peak): Never shrink a bounding box.
`FT_Outline_Get_BBox` can return a box that leaves out an on-curve point.
When a cubic's control points reach above the box's current maximum but the
curve itself stays below it, `cubic_peak` returns a negative value and
`BBox_Cubic_Check` adds it, lowering `*max` (and, the other way, raising
`*min`).

Patch provided by @Lynth-KR.

Fixes issue #1489.
2026-11-19 20:26:25 +01:00
Alexei Podtelezhnikov d7339729da * src/cff/cffparse.c (cff_parse_fixed_dynamic): Optimize condition. 2026-11-17 18:15:46 -05:00
Alexei Podtelezhnikov dbb00e529e [cff] Reduce exponent variables to standard integers.
* src/cff/cffparse.c (cff_parse_real): Update exponent types.
(do_fixed, cff_parse_fixed_{scales,dynamic}, cff_parse_font_matrix):
Update callers.
2026-11-11 17:13:54 -05:00
Alexei Podtelezhnikov d68990db70 * src/cff/cffparse.c (cff_parse_real): Clean up. 2026-11-11 08:28:15 -05:00
Alexei Podtelezhnikov 5b3101f5ef * src/cff/cffparse.c (cff_parse_real): Optimize conditions.
For positive integers, ( a / b >= c ) is equivalent to ( a / c >= b ).
The replacement conditions use shifts instead of divisions.
2026-11-11 08:26:03 -05:00
Alexei Podtelezhnikov 38f5134586 * src/truetype/ttvarc.c (tt_varc_get_item_deltas): Tighten condition.
... because 65537 * 65535 does not wrap around.
2026-11-10 23:15:21 -05:00
Alexei Podtelezhnikov 95968bb00e * src/truetype/ttgxvar.c (tt_var_load_item_variation_store): Update 2.
Note again that ( region_count * axis_count ) does not overflow or
wrap around as those are 15- and 16-bit values. "Six" does it.
2026-11-10 21:49:55 -05:00
Alexei Podtelezhnikov 1b53e33b38 * src/truetype/ttvarc.c (tt_varc_get_item_deltas): Optimize check.
Given 16-bit region_count, the product region_count * num_deltas
can only overflow when num_deltas is more than 65536.  Use it to
avoid many divisions.
2026-11-10 20:52:37 -05:00
Alexei Podtelezhnikov 7244854a48 * src/truetype/ttgxvar.c (tt_var_load_item_variation_store): Update. 2026-11-10 20:17:00 -05:00
Alexei Podtelezhnikov 8f4b128d69 [truetype] Update a frame length check.
Both 'region_count' and 'axis_count' are read as USHORT with the
former further capped at 32767. Their product will never overflow.
It is the multiplication by 6 that does it.

* src/truetype/ttgxvar.c (tt_var_load_item_variation_store): Update.
2026-11-10 20:03:01 -05:00
Yuanx Shi 6065d6a40e [mac] Fix handling of malformed Mac suitcase files.
This is only relevant on macOS platforms.

* builds/mac/ftmac.c (lookup_lwfn_by_fond): Correctly handle and check
  `base_lwfn`, which is a Pascal string.

  (read_lwfn): Check PFB chunk size.

Fixes issue #1481.
2026-11-10 11:23:08 +01:00
Behdad Esfahbod (بهداد اسفهبد) f1f3f7d722 [truetype] Add a frame length check.
This is especially necessary for environments like Windows where `long` is
32-bit.

* src/truetype/ttgxvar.c (tt_var_load_item_variation_store): Add guard for
  variation region list size.

Fixes issue #1484.
2026-11-10 10:52:33 +01:00
Alexei Podtelezhnikov c4a3c188e8 [cache] Use unsigned zero-based ref_count.
* src/cache/ftccache.h (FTC_NodeRec): Change type of ref_count.
* src/cache/ftcmanag.c (FTC_Manager_Compress, FTC_Manager_FlushN,
FTC_Node_Unref): Updated for unsigned ref_count.
2026-11-03 18:07:31 -05:00
Alexei Podtelezhnikov 2045ea3920 [base] Use unsigned zero-based refcounts.
This reverts 67cf7a88 to unsigned refcounts, with conditional decrements.

* include/freetype/internal/ftobjs.c (FT_Face_InternalRec,
FT_LibraryRec): Make `refcount' unsigned.
* src/base/ftobjs.c (FT_New_Library, ft_open_face_internal): Keep it zero.
(FT_Done_Library, FT_Done_Face): ... and decrement it conditionally.
2026-11-03 10:25:11 -05:00
Werner Lemberg 36db6edb84 * src/autofit/ft-hb.c: Code formatting. 2026-11-02 07:03:13 +01:00
Alexei Podtelezhnikov 63e7ef2e61 * src/truetype/ttvarc.c (read_uint32var): Optimize for size. 2026-10-31 14:16:28 -04:00
Behdad Esfahbod 36cd3d56e3 [autofit] Pin dynamic HarfBuzz symbol provider.
`RTLD_DEFAULT` is an ordered process-wide search scope, not a handle for one
library.  When Android's platform HarfBuzz precedes an application-provided
HarfBuzz:

* Common symbols such as hb_version_atleast resolve to the old platform
  copy.
* A symbol absent from that copy can resolve to the newer application copy.
* Resolving every function independently can therefore assemble a function
  table from incompatible HarfBuzz ABIs.

The existing code already avoids loading another HarfBuzz when one is
visible.  The problem is that it continues resolving functions against the
process-wide scope.

* src/autofit/ft-hb.c (ft_hb_funcs_init): Use `RTLD_DEFAULT` only to
  discover HarfBuzz, then resolve the complete API from a concrete provider.

  If the initial provider lacks a required symbol but `RTLD_DEFAULT` finds
  that symbol in another binary, treat the second binary as a new candidate
  and reassess the entire API against its concrete handle (using the
  temporarily defined macro `CHECK_PROVIDER`).  Accept it only if it
  supplies every required function; never retain a mixed table.

  The reassessment is bounded to one retry, preventing incomplete providers
  from cycling.

Fixes issue #1479.
2026-10-30 08:08:59 +01:00
Tim-Philipp Müller 529c6f77a6 ci: bump macOS image to 27 golden gate 2026-10-27 09:34:03 +00:00
Werner Lemberg 3f6dad8e4f * src/truetype/ttvarc.c (read_uint32var): Avoid undefined shift.
Reported as

  https://issues.oss-fuzz.com/issues/578116201
2026-10-27 06:23:06 +01:00
Alexei Podtelezhnikov 3e8df65e4e * src/base/ftcalc.c (FT_Vector_NormLen): Fix issues.
https://issues.oss-fuzz.com/issues/577834291
https://issues.oss-fuzz.com/issues/577758652
2026-10-26 19:42:32 -04:00
Yaroslav K 8f24d5a911 * builds/plan9/README: Fix Plan 9 integration instructions. 2026-10-26 11:12:54 +00:00
Alexei Podtelezhnikov 4ba7c3d82a * src/base/ftcalc.c (FT_Vector_NormLen): Optimize iterations. 2026-10-24 22:42:24 -04:00
Behdad Esfahbod 2b01fa2d67 [truetype] Remove TT_CONFIG_OPTION_NO_BORING_EXPANSION.
Despite its name, this option only gated 'avar' version 2 support.
FreeType 2.15.0 includes the complete boring-expansion set of proposals,
now released as ISO Open Font Format, fifth edition
(ISO/IEC 14496-22:2026).  Gating just avar2 no longer makes sense,
especially since it has also been shipping on Apple platforms for
four years.

* include/freetype/config/ftoption.h, devel/ftoption.h
  (TT_CONFIG_OPTION_NO_BORING_EXPANSION): Remove.
* src/truetype/ttgxvar.c (ft_var_load_avar): Remove configuration guards.

* docs/CHANGES: Updated.

All five Meson regression tests pass with the removed macro still
defined.  avar1 and avar2 coordinate mapping agrees with FontTools.

Assisted-by: OpenAI Codex
2026-10-21 19:57:57 +02:00
Alexei Podtelezhnikov 9d7790e2ee * src/base/ftcalc.c (FT_MulFix, FT_DivFix, FT_MulDiv): Better sign. 2026-10-21 10:08:26 -04:00
Behdad Esfahbod 0eca44e6e8 [truetype] Use the blend axis count for private VARC axes.
Static VARC fonts can have private variation axes without an 'fvar'
table or public MM metadata.  Use the blend's axis count when validating
'avar' and item variation stores, avoiding a null 'mmvar' dereference
when loading HVAR or VVAR for a VARC component.

* src/truetype/ttgxvar.c (ft_var_load_avar,
  tt_var_load_item_variation_store): Use blend->num_axis.

* tests/varc/make-hvvar-fonts.py: Generate HVAR and VVAR fixtures from
  the static VARC/gvar font using only Python's standard library.
* tests/meson.build: Generate the fixtures and pass them to the VARC test.
* tests/varc/main.c (test_font, main): Test generated fixture paths.

Tests: all five Meson regression tests pass.

Fixes issue #1474.

Assisted-by: OpenAI Codex
2026-10-19 06:12:33 +02:00
Alexei Podtelezhnikov a5877f48ff * src/base/fttrigon.c (ft_trig_pseudo_polarize): Another small tweak. 2026-10-17 06:29:59 -04:00
Alexei Podtelezhnikov 632cd1be57 * src/base/fttrigon.c (ft_trig_pseudo_polarize): Small tweak. 2026-10-17 05:07:23 -04:00
Alexei Podtelezhnikov 05f343a64b * include/freetype/internal/ftcalc.h (UABS, ULABS): Fix macros. 2026-10-17 04:27:55 -04:00
Alejandro Pacheco 023fd06e3d [truetype] Bound 'hdmx' advance lookup for incremental glyphs.
With the incremental interface, `tt_glyph_load` accepts glyph indices beyond
`num_glyphs`, but the 'hdmx' records only hold `num_glyphs` widths.

* src/truetype/ttgload.c (TT_Load_Glyph): Don't use `loader.widthp`
  for glyph indices outside of the font's glyph range.
2026-10-14 14:51:37 +02:00
leijurv ed5705292e [base] Remove branching from the CORDIC loops.
This improves performance, fixes #1473.

* src/base/fttrigon.c (ft_trig_pseudo_rotate, ft_trig_pseudo_polarize):
Replace if-else with conditional negation by a mask.
2026-10-14 08:21:13 -04:00
Werner Lemberg 88f8b33c4d subprojects/libpng.wrap: Updated to newest release. 2026-10-13 05:52:53 +02:00
Werner Lemberg ad12863c74 Minor doc fixes. 2026-10-13 05:52:34 +02:00
Werner Lemberg 37515cf56b * Version 2.15.0 released.
==========================

Tag sources with `VER-2-15-0'.

* docs/VERSION.TXT: Add entry for version 2.15.0.
* docs/CHANGES: Updated.
* docs/release, docs/README, builds/macs/README: Updated.

* README, src/base/ftver.rc, builds/windows/vc2010/index.html,
  builds/windows/visualc/index.html, builds/windows/visualce/index.html,
  builds/wince/vc2005-ce/index.html, builds/wince/vc2008-ce/index.html,
  docs/freetype-config.1: s/2.14.3/2.15.0/, s/2143/2150/.

* include/freetype/freetype.h (FREETYPE_MINOR): Set to 15.
(FREETYPE_PATCH): Set to 0.

* builds/unix/configure.raw (version_info): Set to 26:7:20.
* CMakeLists.txt (VERSION_MINOR): Set to 15.
(VERSION_PATCH): Set to 0.
VER-2-15-0
2026-10-11 22:46:16 +02:00
Werner Lemberg 27ed2650a9 Whitespace. 2026-10-11 07:34:16 +02:00
Behdad Esfahbod e2526d30e6 [truetype] Avoid overflow in VARC axis values.
Reported as

  https://issues.oss-fuzz.com/issues/570754474

* src/truetype/ttvarc.c (tt_varc_parse_component): Use `MUL_INT32` for
  converting 32-bit packed axis values from `F2DOT14` to `F16DOT16`.

  (tt_face_load_varc_glyph): Use `NEG_LONG` when rounding negative axis
  values, since the conversion can wrap to `INT32_MIN` and negating that
  value overflows on platforms with 32-bit longs.

Assisted-by: OpenAI Codex
2026-10-09 06:51:32 +02:00
Kalt2212 79d80cadfc * src/psaux/psintrp.c (cf2_doBlend before multiplying): Avoid overflow.
`numBlends` comes from the charstring and is attacker-controlled.  Check for
overflow before multiplying: a wrapped `numOperands` would bypass the stack
underflow check below and the loop that follows would then run up to 2^32
iterations (CPU exhaustion).
2026-10-08 11:11:44 +02:00
Behdad Esfahbod (بهداد اسفهبد) 3f12a8a617 [autofit] Limit default GSUB coverage to reachable glyphs.
A lookup can be registered under several scripts while substituting inputs
from only one of them.  Collecting every output assigns those glyphs to the
first processed script, regardless of the inputs' styles.  In Google Sans
this assigns the Latin rvrn alternates to Cyrillic; missing Cyrillic blue
zones then disable their hinting and darkening.

* src/autofit/afshaper.c (af_shaper_get_coverage_hb): Seed default coverage
  with glyphs already assigned to the style and compute their substitution
  closure through the collected lookups.
  Keep the special feature coverages and their style precedence intact.

* src/autofit/ft-hb-decls.h: Add `hb_ot_layout_lookups_substitute_closure`.

* tests/issue-1441/*: New files, adding synthetic regression fonts covering
  shared lookups, both feature variation records, chained substitutions,
  ligatures, DFLT-only features, unreachable outputs, and preservation of
  the small-cap style.

The full Meson test suite passes with linked, dynamic, and disabled
HarfBuzz.  The regression fails before the fix.  Google Sans alternates
retain Latin styles and stem darkening after the fix.

Assisted-by: OpenAI Codex

Fixes issue #1441.
2026-10-08 06:14:26 +02:00
Alexei Podtelezhnikov d5d4bef0c6 [truetype] Make tiny exception from v40 rules.
* src/truetype/ttinterp.c (Direct_Move): Make v40 exception for
horizontal projection to fix glitches in Comic Sans MS.
2026-10-06 10:11:29 -04:00
Alexei Podtelezhnikov 25167984d2 * src/type1/t1parse.c (T1_Get_Private_Dict): Fix a leak. 2026-10-04 16:09:18 -04:00