Commit graph

1038 commits

Author SHA1 Message Date
Debbie Goldsmith
0c9b8e9e93 Support Hierarchical Variable Fonts (HVF) using Apple's 'libhvf' library.
The new 'hvf' module is a thin wrapper around 'libhvf' with the necessary
boilerplate stuff to integrate it into FreeType.  Note that this currently
works on macOS >= 15.4 and iOS >= 18.4 only.

* include/freetype/tttags.h (TTAG_hvgl, TTAG_hvpm): New macros.
* include/freetype/config/ftmodule.h: Add `hvf_driver_class`.
* include/freetype/internal/fttrace.h: Add tracing tags `hvfdrv`, `hvfobjs`,
  and `hvfload`
* include/freetype/internal/services/svfntfmt.h (FT_FONT_FORMAT_HVF): New
  macro.

* modules.cfg (FONT_MODULES): Add `hvf` module.

* src/sfnt/sfobjc.s (sfnt_init_face): Handle 'hvgl' table.

* src/hvf/*: New files.
2026-03-23 19:36:36 +01:00
Alexei Podtelezhnikov
3d7c50d13c [sfnt/COLRv0] Revise sanity checks.
This re-implements 6d62076a and potentially fixes #1404. 

* src/sfnt/ttcolr.c (tt_face_get_colr_layer): Rely on validated total num_layers.
2026-03-19 12:26:32 -04:00
Werner Lemberg
264b5fbf5b Update all copyright notices. 2026-03-11 17:27:07 +01:00
Werner Lemberg
1c6e43ab90 * src/sfnt/ttgpos.c (tt_face_load_gpos): Correctly release gpos.
This is a follow-up to issue #1398.
2026-03-09 20:34:55 +01:00
Dominik Röttsches
45556a19aa [sfnt] Use array count in sanitization of BaseGlyphPaintRecord list.
* src/sfnt/ttcolr.c (tt_face_load_colr): Compute correct length
  of `BaseGlyphPaintRecord` array size.

Fixes issue #1397.
2026-03-09 10:44:19 +01:00
Werner Lemberg
a1079b181e * src/sfnt/ttgpos.c (tt_face_validate_pair_pos2): Correct limit check.
Fixes issue #1398.
2026-03-09 05:50:43 +01:00
Werner Lemberg
5d249d8402 * src/sfnt/ttgpos.c (tt_face_get_pair_pos1_kerning): Typo.
This could lead to make FreeType miss some kerning pairs.

Fixes issue #1393.
2026-03-06 06:55:07 +01:00
Werner Lemberg
b2c8a031a2 * src/sfnt/ttgpos.c (tt_face_get_class): Fix range check.
Fixes issue #1392.
2026-03-06 06:32:10 +01:00
Alexei Podtelezhnikov
be8e126ae0 [base] Clean up bitmap allocations.
* src/base/src/base/ftobjs.c (ft_glyphslot_alloc_bitmap): Use preset
dimensions and call FT_MEM_ALLOC_MULT.
* include/freetype/internal/ftobjs.h (ft_glyphslot_alloc_bitmap):
Updated signature...
* src/*: ... and all callers.
2026-02-20 22:50:50 -05:00
Alexei Podtelezhnikov
156c7ea38f * src/sfnt/ttcolr.c (tt_face_colr_blend_layer): Use FT_ALLOC_MULT.
Fixes #1389. The overflow is detected in ft_mem_qrealloc.
2026-02-20 07:55:43 -05:00
Alexei Podtelezhnikov
676e8b8637 * src/sfnt/ttgpos.c (tt_face_validate_*): Fix check signedness.
This is an alternative to !398 without signed -1.
2026-02-03 20:16:32 -05:00
Alexei Podtelezhnikov
28407bc8cd * src/sfnt/sfwoff2.c (reconstruct_glyf): Revise variables.
This should fix #1379 while resonstructing the code intent.
2026-01-27 19:41:17 -05:00
Werner Lemberg
f75ae3d06d * src/sfnt/ttbdf.c (tt_face_load_bdf_props): Fix size test.
This prevents a potential overflow on 32bit systems.

Problem reported by Zhao Zijie <zijie4@illinois.edu>.
2025-12-04 07:51:39 +01:00
Werner Lemberg
5751c184cc Improve documentation of the 'BDF ' table as used in X11 .otb files.
Also do some minor code formatting.
2025-12-04 07:46:36 +01:00
Werner Lemberg
b848824d10 [sfnt] Fix GPOS handling.
Problem reported by Marc Schönefeld.

* src/sfnt/ttgpos.c (tt_face_validate_lookup_table, tt_face_load_gpos): Fix
  counting of fitting subtables by correctly rejecting invalid data.
2025-11-28 14:19:37 +01:00
Werner Lemberg
32cb53904c Update all copyright notices. 2025-09-06 06:14:03 +02:00
Werner Lemberg
d3668e00da src/sfnt/ttload.c (tt_face_load_any): Correctly handle font containers.
Reported as

  https://issues.oss-fuzz.com/issues/424613326
2025-09-05 20:23:22 +02:00
Werner Lemberg
b04db3872c [sfnt] Rewrite GPOS kerning support. (2/2)
The previous code had a fundamental flaw: it didn't validate the necessary
parts of the 'GPOS' table before accessing it, causing crashes with
malformed data (since `TT_CONFIG_OPTION_GPOS_KERNING` is off by default,
standard fuzzers don't catch these problems).  Additionally, it did a lot of
parsing while accessing kerning data, making it rather slow.

The new implementation fixes this.  After validation, offsets to the 'GPOS'
lookup subtables used in the 'kern' feature that correspond to 'simple'
kerning (i.e., similar to 'kern' table kerning) are stored in `TT_Face`;
this greatly simplifies and accelerates access to the kerning data.

Testing with font `SF-Pro.ttf` version '1.00', the validation time for the
'GPOS' table increases the start-up time of `FT_New_Face` by less than 1%,
while calls to `FT_Get_Kerning` become about 3.5 times faster.

* include/freetype/internal (gpos_kerning_available): Replace with...
  (gpos_lookups_kerning, num_gpos_lookups_kerning): ... these new fields.
  Update callers.

* src/ttgpos.c [TT_CONFIG_OPTION_GPOS_KERNING]: A new implementation.
2025-07-05 14:51:40 +02:00
Werner Lemberg
8ef26a803c [sfnt] Rewrite GPOS kerning support. (1/2)
This commit removes the previous implementation.
2025-07-05 14:51:40 +02:00
Werner Lemberg
fb6a74269d * src/sfnt/ttkern.h (TT_FACE_HAS_KERNING): Remove macro.
Given that we also support (limited) 'GPOS' table kerning if
`TT_CONFIG_OPTION_GPOS_KERNING` is defined, the name of this macro is
misleading since it only is true for 'kern' table kerning.

* src/sfnt/sfobjs.c (sfn_load_face): Replace `TT_FACE_HAS_KERNING` with
  plain code.
2025-07-05 14:51:40 +02:00
Werner Lemberg
8d82c9fa4d */*: Fix trivial signedness issues with format strings in trace messages.
As reported with clang 19's `-Wformat` option.
2025-07-01 17:08:37 +02:00
Werner Lemberg
7f559fbe9a Update links.
Found with `linkchecker --check-extern index.html` running locally in the
'freetype-web' repository.
2025-06-10 04:56:50 +02:00
Werner Lemberg
5a07f41d0e [sfnt] FT_Load_Sfnt_Table can now also load a font's table directory.
Closes issue #1263.

* src/sfnt/ttload.c (tt_face_load_any): Implement it.
2025-05-28 09:52:44 +02:00
Behdad Esfahbod
5987a9f51d [ttmtx] Fix check for being non-default variation position.
If user explicitly sets variations to `NULL` after it being set to something
else, `face->blend` will still be non-`NULL`.  The intention here however is
correctly captured by `FT_IS_VARIATION`.

* src/sfnt/ttmtx.c (tt_face_get_metrics): Use `FT_IS_VARIATION`.
2025-05-23 08:23:51 +02:00
Werner Lemberg
6fa8725a41 [sfnt] Avoid allocation bomb in compressed SVG documents.
Reported as

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

* src/sfnt/ttsvg.c (MAX_SVG_SIZE): New macro.
  (tt_face_load_svg_doc): Reject too large buffer.
2025-05-09 13:27:51 +02:00
Alexei Podtelezhnikov
1beb83fd12 * src/sfnt/ttsbit.c (tt_face_load_sbix_image): Refactor flip. 2025-01-01 22:28:36 -05:00
Alexei Podtelezhnikov
83af801b55 * src/sfnt/ttsbit.c (tt_face_load_sbix_image): Respect metrics_only.
Also fixes recursive flip.
2024-09-07 13:44:57 -04:00
Alexei Podtelezhnikov
3008032062 * src/sfnt/ttsbit.c (tt_face_load_sbix_image): Tweak loop. 2024-09-06 13:43:47 +00:00
Andrew Murray
98283cb30f [sfnt] Support sbix graphicType 'flip'.
* src/sfnt/ttsbit.c (tt_face_load_sbix_image): Currently undocumented by
Apple, this flips the bitmap data horizontally.  It is used on macOS in
Apple Color Emoji; 19.4d6e1; 2024-02-05 (file `Apple Color Emoji.ttc`).

Fixes issue #1282.
2024-09-06 10:10:23 +02:00
Alexei Podtelezhnikov
d2612e1c3f * src/sfnt/ttcmap.c (tt_cmap*_get_info): Remove casting. 2024-08-26 07:01:19 -04:00
Werner Lemberg
6b992aaaf2 * src/*/*: Fix C++ compilation; fix clang warnings. 2024-08-12 12:34:28 +02:00
Werner Lemberg
ed8b82ba94 Various minor documentation or formatting fixes. 2024-08-12 12:34:28 +02:00
Alexei Podtelezhnikov
3f8edd234d * src/sfnt/ttload.c (tt_face_load_name): Shorten dereference. 2024-07-28 20:56:07 -04:00
Alexei Podtelezhnikov
2488854056 [bdf,pcf,winfonts,sfnt] Remove barely used marcros.
* include/freetype/internal/ftobjs.h (FT_FACE_SIZE, FT_SIZE_FACE):
Removed.
* src/bdf/bdfdrivr.c (BDF_Glyph_Load): Updated.
* src/pcf/pcfdrivr.c (PCF_Glyph_Load): Ditto.
* src/winfonts/winfnt.c (FNT_Load_Glyph): Ditto
* src/sfnt/ttbdf.c (tt_face_find_bdf_prop): Ditto.
2024-07-28 19:42:49 -04:00
Werner Lemberg
bab9564a97 Make 'multi' build work again.
* src/psaux/psobjs.c: Include `psft.h`.

* src/sfnt/rules.mk (SFNT_DRV_SRC): Add `ttgpos.c`.

Fixes issue #1284.
2024-06-26 05:41:36 +02:00
Ben Wagner
5858fa16ca [colr] Avoid overflow in range checks
In 32 bit builds `FT_ULong` is 32 bits and can silently overflow when a
large number is read into one and then it is summed or multiplied with
another number.  Checks for range overflow must be written so that they
themselves do not overflow.  Also ensure that the table_size is always the
first part of the range check and consistently use `<` or `<=`.

* src/sfnt/ttcolr.c (tt_face_load_colr): Avoid overflow.
(find_base_glyph_v1_record): Remove old work-around.

Bug: https://issues.chromium.org/issues/41495455
Bug: https://issues.chromium.org/issues/40945818
2024-05-08 05:01:16 +02:00
Alexei Podtelezhnikov
7bd887f177 * src/sfnt/sfwoff2.c (woff2_open_font): Fix copy-paste typo. 2024-05-03 16:04:35 +00:00
Alexei Podtelezhnikov
3f28a6b6af [woff,woff2] Limit the number of tables and use FT_MSB.
The upper limit of 4095 is implied by the SFNT header format
where the multiplication by 16 would overflow without it.

* src/sfnt/sfwoff.c (woff_open_font): Updated.
* src/sfnt/sfwoff2.c (woff2_open_font): Ditto.
2024-05-03 15:44:57 +00:00
Ben Wanger
13d1180f45 [woff2] Disallow zero table font entries
The existing code already disallows zero table woff2 overall, but still
allows for individual CollectionFontEntry to create font instances with
zero tables. Such fonts are not useful so error early.

This also fixes an MSAN discovered issue where if a CollectionFontEntry
numTables is zero then the sfnt_header was not fully initialized.

* src/sfnt/sfwoff2.c (woff2_open_font): error on zero tables, always
initalize sfnt_header

Fixes: https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=68384
2024-05-02 15:00:27 -04:00
Alexei Podtelezhnikov
4d50468478 [sfnt] Use faster macros in checksums.
* src/truetype/ttobjs.c (tt_synth_sfnt_checksum): Use FT_NEXT_XXX.
* src/sfnt/sfwoff2.c (compute_ULong_sum): Use macros.
2024-05-01 23:19:31 -04:00
Alexei Podtelezhnikov
13da904267 * src/sfnt/sfwoff2.c (compute_ULong_sum): Clean up. 2024-05-01 00:34:21 -04:00
Ben Wanger
f42ce25563 [colr] Ensure enough bytes for PaintColrLayers
* src/sfnt/ttcolr.c (read_paint): check that there are five additional
bytes to be read when reading PaintColrLayers.

Reported as

  https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=66566
2024-03-08 14:55:12 -05:00
Alexei Podtelezhnikov
47574f7ea4 Update all copyright notices. 2024-01-27 11:11:22 -05:00
Alexei Podtelezhnikov
4f0256c13f * src/sfnt/ttgpos.c (tt_gpos_get_glyph_class): Fix warning C4018. 2024-01-27 10:47:10 -05:00
David Saltzman
8f286c86ef Add support for kerning from 'GPOS' tables.
This commit adds support for kerning from 'GPOS' tables, while maintaining
support for basic 'kern' tables.  `FT_HAS_KERNING` will be true for a font
with either available and `FT_Get_Kerning` will still use the basic 'kern'
table data if avilable, otherwise check the GPOS 'kern' feature.

This feature is disabled by default; it can be enabled with the
`TT_CONFIG_OPTION_GPOS_KERNING` flag.

Only basic kerning (pair positioning with just an x advance) is supported
from the GPOS layout features; support for that was added to make the
existing `FT_Get_Kerning` API more consistently functional.  FreeType does
not intend to extend itself to further GPOS functionality though; a
higher-level library like HarfBuzz can be used instead for that.

* include/freetype/config/ftoption.h, include/devel/ftoption.h
(TT_CONFIG_OPTION_GPOS_KERNING): New configuration option.

* include/freetype/internal/fttrace.h: Add `ttgpos` trace handler.

* include/freetype/internal/sfnt.h (SFNT_Interface): Add `load_gpos` and
`get_gpos_kerning` fields.
(FT_DEFINE_SFNT_INTERFACE): Updated.

* include/freetype/internal/tttypes.h: Include `fttypes.h`.
(TT_FaceRec) [TT_CONFIG_OPTION_GPOS_KERNING]: Add `gpos_table` and
`gpos_kerning_available` fields.

* src/sfnt/ttgpos.c, src/sfnt/ttgpos.h: New files.

* src/sfnt/sfdriver.c [TT_CONFIG_OPTION_GPOS_KERNING]: Include `ttgpos.h`.
(sfnt_interface): Updated.

* src/sfnt/sfnt.c: Include `ttgpos.c`.

* src/sfnt/sfobjs.c [TT_CONFIG_OPTION_GPOS_KERNING]: Include `ttgpos.h`.
(sfnt_load_face) [TT_CONFIG_OPTION_GPOS_KERNING]: Load and free GPOS kerning
data; check GPOS kerning availability.

* src/truetype/ttdriver.c (tt_get_kerning): Use GPOS kerning if there's no
'kern' table.
2024-01-27 10:55:04 +01:00
Ozkan Sezer
7bac4d146a * src/sfnt/ttcolr.c (find_base_glyph_v1_record): Fix build in C90 mode. 2024-01-08 20:27:03 +01:00
Alexei Podtelezhnikov
4a85ff0b79 [sfnt] Restrict POST version 1.0.
A font has surfaced with `post` version 1.0 and fewer than 258 glyphs.
Its glyphs did not correspond to their names. We now reject such `post`
strictly following specifications.

* src/sfnt/ttpost.c (tt_face_get_ps_name): Check the number of glyphs
for version 1.0.
2024-01-04 21:38:51 -05:00
Werner Lemberg
57c4252ab5 [sfnt] Guard access in 'COLR' v1 glyph binary search.
Reported as

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

* src/sfnt/ttcolr.c (find_base_glyph_v1_record): Guard access of the search
pointer during binary search.  The pointer needs to be checked as we go as
the test that compares number of v1 glyphs with table size at the time of
loading the table is not sufficient on its own.

A scenario is possible in which the `BaseGlyphRecord` list extends into
non-`BaseGlyphRecord` parts of the 'COLR' v1 table (but passed the size
comparison check).  Then, at those locations, invalid glyph ID values are
read and may provoke an invalid read due to reassigning min and max values
during the binary search.
2024-01-02 17:55:33 +01:00
Alexei Podtelezhnikov
4904d1eb1b * src/sfnt/ttpost.c (load_format_20): Micro-optimize. 2023-09-06 22:58:46 -04:00
Alexei Podtelezhnikov
000b26a30f * src/sfnt/ttpost.c (load_format_20): Rework tracing. 2023-08-30 23:03:02 -04:00