Commit Graph
155 Commits
Author SHA1 Message Date
Behdad EsfahbodandClaude Opus 4.8 db0231fc12 [subset] Free the replaced override string in override_name_table()
name_table_overrides stores hb_malloc()ed strings as plain hb_bytes_t
values, so the invariant that every stored string is freed exactly once
in ~hb_subset_input_t broke when set() silently overwrote an existing
key: overriding the same name record more than once on one input leaked
the previous copy, and so did a NULL (remove) after a non-empty
override.

hb_subset_input_override_name_table() is the only place that allocates
these strings, so fix it there: look the record up with has(&old) and
fini() it in place before set() (fini nulls the pair, so no path frees
twice, and the lookup happens before set() can reallocate the table).
Also free the fresh copy and return false when set() cannot store it,
instead of leaking it and returning true.  hb_subset_plan_t copies the
map and frees its own copies, so it is unaffected.  No public API/ABI
change.

A regression line in test_subset_name_overrides overrides one record
twice; only the last string survives and the first must not leak.

Reported by Anthropic's OSS Scanner as ordinary bug ANT-2026-8SA3SRW4.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-10-30 15:26:52 -06:00
Behdad EsfahbodandClaude Opus 4.8 9c093444ef [subset] Honour len in hb_subset_axis_range_from_string()
The function documents len as the length of str, but located the ':'
separators with strpbrk() and matched "drop" with strcmp(), both of
which scan to the next NUL byte.  A caller passing an exact-length,
non-NUL-terminated slice therefore got an out-of-bounds read, and bytes
beyond len could change or reject the parsed range.

Bound every scan by str+len: each strpbrk() becomes memchr() bounded by
end, the strcmp() becomes a len==4 && hb_memcmp() check, and the empty
-piece test !*str becomes str == end.  This is the same discipline the
sibling parsers hb_feature_from_string()/hb_variation_from_string()
already follow.  For len == -1 (the only in-tree caller) len becomes
strlen() first, so behaviour is unchanged.  No public API/ABI change.

A regression test in test/api/test-subset.c passes prefixes of longer
literals with an explicit len and checks the NUL-terminated cases still
parse as before.

Reported by Anthropic's OSS Scanner as ordinary bug ANT-2026-IL9ZX304.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-10-30 15:26:47 -06:00
Behdad Esfahbod 6156c7b4a7 [subset] Validate custom glyph mappings before assigning output ids (#6479)
Glyph zero is always reserved for .notdef. Reject mappings that assign
another retained glyph to it, so the output list has one entry per id.

Also bound the resulting glyph count by the widest supported count
field, MAXP's HBUINT24. Account for the unmapped glyphs and the initial
slot before assigning ids, avoiding wraparound and oversized counts in
table subsetters. The limit applies to the count, not the highest id.

Document these constraints and test valid renumbering, gaps, ignored
remapping of .notdef, reserved-id collisions, and out-of-range counts.
The regression and stock hb-subset both reproduce the issue under ASan
before the fix. All 293 tests pass after it, including the subset suite;
the API subset tests and command-line checks also pass ASan and UBSan.

Discovered by Anthropic's OSS Scanner, as vulnerability
ANT-2026-6I1RIFMQ.

Assisted-by: OpenAI Codex
2026-10-29 21:01:05 -06:00
Ebrahim 9cf8b485c7 [subset] Avoid use of undefined behavior in calling hb_parse_double 2026-10-09 06:04:13 +03:30
Behdad Esfahbod c011af18b9 [subset] Use set iterators when formatting input
Walk tag sets and sorted glyph-map keys through their native iterators
instead of repeatedly calling the public scalar set API.

Tests: meson test -C build (272/272)

Assisted-by: OpenAI Codex <codex@openai.com>
2026-08-20 02:48:34 -06:00
Garret Rieger d7861576ae More fixes for review comments. 2026-07-14 16:26:49 -06:00
Garret Rieger 2725565dab Address review comments. 2026-07-14 16:26:49 -06:00
Garret Rieger 99380f0e44 Add new hb_subset_input_to_command_line_or_fail().
This generates an equivalent hb-subset command line string for a given subset input.

Assisted by gemini.
2026-07-14 16:26:49 -06:00
Behdad Esfahbod 17f7701f9c [subset] Update axis-pinning docs: partial instancing is supported
Partial instancing has long worked for glyf fonts, and now works for CFF2
too; drop the outdated all-axes-must-be-pinned claim.
2026-07-03 21:38:38 -06:00
Takeru Suzuki 689383d05b [subset] keep East Asian spacing palt by default (#6007)
`palt` (Proportional Alternate Widths) is widely used in Japanese
typography but was not retained in the default subset layout features,
unlike its vertical counterpart `vpal` and the closely related `halt`
/ `vhal` / `chws` / `vchw` already kept by default. As a result,
subsetting silently stripped `palt` data, and downstream CSS
`font-feature-settings: "palt"` had no effect.

Add `palt` to the default layout features list alongside the other
East Asian spacing features.

Verified locally with `meson test -C build` (240/240 OK, 0 failures)
and by subsetting NotoSansJP-Bold.ttf with `hb-subset`: `palt` is
stripped on main and retained with this patch, while the other CJK
spacing features (`halt`, `vpal`, `vhal`) are unaffected.

Fixes: https://github.com/harfbuzz/harfbuzz/issues/6006

Assisted-by: Claude
2026-05-29 03:19:18 -06:00
Behdad Esfahbod a46b93208a [subset] Remove printf from library! 2025-04-05 23:27:15 -06:00
Khaled Hosny 7b27c8edd4 10.2.0 2025-01-11 18:13:18 +02:00
Qunxin Liu 3bb89eebd6 [instancer] use hb_parse_double() for parsing axis positions
Added hb_subset_axis_range_from/to_string()
2024-11-25 09:38:13 -07:00
Emanuel Czirai dce8e45799 typo acsii -> ascii in hb-subset-input.cc 2024-06-24 19:29:54 -06:00
Behdad Esfahbod 3fa47cea27 [subset] Add HB_SUBSET_FLAGS_NAME_LEGACY to keep_everything()
Fixes https://github.com/harfbuzz/harfbuzz/issues/4739
2024-05-30 17:39:33 -06:00
Khaled Hosny 71b1ba7aa6 8.5.0 2024-05-13 23:42:50 +03:00
Garret Rieger 3f38ffd633 [subset] Fix remaining double conversion warnings. 2024-05-13 13:18:27 -07:00
Garret Rieger 4cf606f674 [instancer] Promote partial instancing api out of experimental. 2024-05-02 21:22:18 +00:00
Khaled Hosny 2b3631a866 8.3.1 2024-03-17 07:50:59 +02:00
Qunxin Liu cfbb6a6872 [subset] support BASE table subsetting (#4618)
* [subset] support BASE table

* [subset] add tests for BASE table subsetting
2024-03-14 18:33:34 -06:00
Qunxin Liu d6431dc7e6 [instancer] support *=drop, which would pin all axis to default location 2024-03-07 12:24:43 -07:00
Garret Rieger 66a404cad4 [subset] Fix hb_subset_input_get_axis_range documentation. 2023-11-15 21:41:30 +00:00
Garret Rieger d30c1dacf5 Add test suite for instancing option parsing. 2023-11-15 20:16:07 +00:00
Garret Rieger 43236ce345 [instancer] add the option to leave blanks in the min:def:max syntax.
When parsing axis positions in the --variations flag recognize empty values as meaning the existing value for that part. For example:

:300:500

Specifies min = existing, def = 300, max = 500.

See: https://github.com/fonttools/fonttools/issues/3322
2023-11-15 17:54:56 +00:00
一丝 b0150ffd05 [subset] keep East Asian spacing vhal, halt, chws, vchw by default
Closes: https://github.com/harfbuzz/harfbuzz/issues/4451
2023-10-20 10:18:58 -06:00
Qunxin Liu 45c2d05d00 [instancer] add subset() for MVAR 2023-09-18 12:20:36 -07:00
Qunxin Liu 32cfa37e2e [instancer] command line support for partial instancing
-Also updated hb_subset_input_set_axis_range (), so user can define
default value as well
2023-08-07 14:37:13 -07:00
Qunxin Liu 0065658e96 [instancer] enable cvar instancing code 2023-08-07 11:12:02 -07:00
Qunxin Liu 13f05ab9b3 [instancer] support avar table partial instancing 2023-07-20 12:37:42 -07:00
Qunxin Liu 58f68dd37a [instancer] wrap hb_subset_input_Set_axis_range() under experimental
Also add notes: it's not actually working yet.
2023-05-12 11:09:04 -06:00
Qunxin Liu 22cca43ded [instancer ]update internal hashmap to use Triple instead of single value
-Added hb-subset-instancer-solver.hh file and moved Triple struct to the
head file
2023-05-12 11:09:04 -06:00
Qunxin Liu 0799afe2b6 [instancer] Add hb_subset_input_set_axis_range() API 2023-05-12 11:09:04 -06:00
Khaled Hosny 4584bcdc32 7.3.0 2023-05-10 00:20:25 +03:00
Garret Rieger 8eb9f31263 [subset] s/Since/XSince/. 2023-05-05 15:56:50 +00:00
Garret Rieger d339298f37 [subset] fix hb_subset_input_old_to_new_gid_mapping method comment. 2023-05-05 06:00:30 +00:00
Garret Rieger 3021b2dbe2 [subset] change glyph mapping api to return a mutable map.
Maintains consistency with our other set based api methods.
2023-05-05 05:57:05 +00:00
Garret Rieger 77a8155425 [subset] Add some basic tests for a provided glyph map. 2023-05-04 23:01:56 +00:00
Garret Rieger 98e73192f4 [subset] Add command line flag to provide a gid mapping. 2023-05-04 22:20:06 +00:00
Garret Rieger e14020b27a [subset] remove return value from mapping setting function. 2023-05-04 19:55:32 +00:00
Garret Rieger 6826634714 [subset] apply the user supplied glyph map. 2023-05-04 19:55:32 +00:00
Garret Rieger e711e305c8 [subset] Add new subsetting API method to receive a user specified glyph mapping. 2023-05-04 19:55:32 +00:00
Qunxin Liu a975ec4842 [instancer] apply cvar deltas 2023-02-27 17:05:23 -07:00
Khaled Hosny 8bdaeddfcd 7.0.0 2023-02-11 23:52:58 +02:00
Khaled Hosny 0ea8bbd91a [doc] Use XSince for REPLACEME/EXPERIMENTAL
To hide them from gtk-doc so that we can finally enable gtkdoc-check.
2023-02-11 20:59:44 +02:00
Garret Rieger 2b6d74b42e [subset] for keep everything, don't drop any tables. 2023-01-31 11:16:53 -07:00
Behdad Esfahbod 26d69e059d [subset-input] Move constructor to .cc file 2023-01-12 12:46:44 -07:00
Behdad Esfahbod a916ad9ea9 [subset-input] Move initialization to constructor 2023-01-12 12:44:16 -07:00
Behdad Esfahbod 875f9f6f22 [subset-input] Use shared_ptr for sets 2023-01-12 12:37:48 -07:00
Behdad Esfahbod ef005bc82a [subset-input] Fix destruction
Ouch! Object was already destroyed at that point before.
2023-01-12 12:09:50 -07:00
Behdad Esfahbod e78a68bf46 [subset-input] Don't RETAIN_GIDs in keep-everything 2023-01-11 15:34:11 -07:00