Commit Graph
15 Commits
Author SHA1 Message Date
Wei-Lun Li d1520e8007 [GPOS] Clamp anchor coordinates when converting them from float (#6587)
Anchor coordinates are scaled as float, and apply_cursive_attachment()
and the mark attachment code converted them to hb_position_t with a
plain cast or an implicit conversion. A value out of range for the
target type makes that conversion undefined; on x86 it gives INT32_MIN.
#6154 made the additions around these conversions saturate, but not
the conversions themselves.

With NotoNastaliqUrdu-Regular.ttf at a scale of INT32_MAX, a cursive
anchor scales to 2.23e9, and the glyph ended up with an x_advance of
-2147483648.

Convert with hb_clamp_to(), and negate the cursive cross-direction
offsets with hb_saturate_neg(), since they can now be INT32_MIN.
Results that fit do not change.

Tested with test-shape under UBSan: the new test fails on the base
commit at CursivePosFormat1.hh:141 and passes here. No test reaches
the two conversions in MarkArray.hh; they are changed to match.

Assisted-by: Claude
2026-11-08 12:33:39 -06:00
Behdad EsfahbodandClaude Opus 4.8 5ef8ef9281 [kerx] Charge format-4 control-point actions' contour-point lookups to max_ops
A kerx format-4 control-point action asks the font for two glyph
contour points, which the font functions may satisfy by loading the
whole glyph outline (two full FT_Load_Glyph calls with hb-ft).  The
state-machine driver charges a non-advancing transition only one op,
so a looping entry turned the whole work budget into glyph loads:
two letters and a 680-byte font stalled hb_shape() for seconds.

Charge 2 * HB_BUDGET_256 to buffer->max_ops at the action, before the
callbacks, using the same decrement-and-return idiom morx insertion
uses; once the budget is spent the action is skipped and the driver's
existing max_ops check forces the machine forward.

The sibling GPOS AnchorFormat2 contour-point path has the same
uncharged callback but lives in the layout subsystem and is left for
a separate change.  GDEF CaretValueFormat2 also calls it but only
from hb_ot_layout_get_ligature_carets, bounded per API call.

Regression test in test/api/test-shape.c uses a counting
glyph_contour_point callback on a builder-made looping kerx font
(131074 calls before, <= 256 after).

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

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-11-02 10:52:07 -06:00
Behdad EsfahbodandClaude Opus 4.8 e95283e73e [harfrust] Report shaping failures via hb_buffer_allocation_successful() (#6545)
HarfRust signals a shaping failure -- a max_ops / preprocessing-budget trip, an allocation failure, or an internal error -- by returning false from its shape function, whereas the ot shaper always returns true and reports such failures through the buffer's success flag.

Because hb_shape() returns void, hb_buffer_allocation_successful() is the only failure signal its callers have. The HarfRust shim returned false without touching the C hb_buffer_t, so after a HarfRust budget trip hb_buffer_allocation_successful() still reported success while the buffer was left unshaped.

Mirror the ot shaper in hb-harfrust.cc: always return true and, on failure, mark the buffer unsuccessful. As with the ot shaper after a budget trip, the buffer is then labelled GLYPHS but its contents must not be trusted; the caller must check hb_buffer_allocation_successful().

Add a test-shape regression test that drives the HarfRust shaper with many ranged features (overrunning setup_masks()'s op budget) and asserts the failure now reaches hb_buffer_allocation_successful(). It runs in the test-shape-harfrust CI job and skips when HarfRust is not built.

Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
2026-11-01 19:14:38 -07:00
Behdad EsfahbodandClaude Opus 4.8 f5ab3f4ca2 [test] Force the ot shaper in the cluster re-merge budget test
test_shape_overlong_cluster_remerge checks the native cluster re-merge op
budget added in hb-buffer.cc, which only the "ot" shaper exercises. Under
HB_SHAPER_LIST=harfrust the harfrust shaper handles clusters itself and
never trips that budget, so the buffer stayed allocation-successful and the
test aborted in the rust CI job. Pin the test to hb_shape_full() with an
"ot" shaper list.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-10-30 17:05:41 -06:00
Behdad EsfahbodandClaude Opus 4.8 6202af118b [buffer] Charge cluster re-merge walks to max_ops
The work budget (max_ops) is meant to bound every buffer pass whose
length the font or text controls, but the same-cluster walks that
re-merge a neighbouring run were never charged:

 - the backward merge in delete_glyph() (reached from an empty
   MultipleSubst Sequence);
 - its copy in delete_glyphs_inplace() (default-ignorable / AAT
   glyph deletion);
 - the "extend" and cross-buffer continuation loops in
   merge_clusters_impl() / merge_out_clusters_impl() (reached from
   the Thai/Lao shaper, the normalizer, morx ligatures, and any
   ligature/multiple substitution).

Once one long same-cluster run exists, every further merge or
deletion next to it walks the whole run again, so a single hb_shape()
call does O(N^2) work the budget never sees: e.g. U+0E01 followed by
130,000 x U+0E33 takes ~21 s.

Charge the glyphs actually walked to max_ops and fail the buffer when
the budget is gone, following shift_forward()/move_to(), and skip the
walk once the buffer has failed (delete_glyphs_inplace() and the
shaper-level merge_clusters() callers keep calling after a failure).
merge_out_clusters_impl() also gains the "cluster != ..." guards that
merge_clusters_impl() already had, so it no longer walks a run that
already holds the merged value; set_cluster() is a no-op on such a
glyph, so output is unchanged.  Verified: default-direction Thai
output is byte-identical to before at sizes that fit the budget, and
pathological inputs now end with hb_buffer_allocation_successful() ==
false, like any other max_ops exhaustion.

Regression test added to test/api/test-shape.c using a stock font.

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

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-10-30 15:24:10 -06:00
Behdad Esfahbod a597884edf [GPOS] Saturate immediate mark offsets
Mark-to-mark attachment can accumulate an unbounded cross-direction
offset. Clamp anchor conversion and saturate the immediate addition so
overlong mark clusters stop at hb_position_t limits instead of invoking
signed-overflow undefined behavior.

Add a regression for issue #6151 using 35,000 combining marks.

Testing: meson test -C build --print-errorlogs

Assisted-by: Codex <codex@openai.com>
2026-08-12 17:17:00 -06:00
Behdad Esfahbod 155e1e633b [test/api] Use g_assert_true instead of g_assert
The latter terminates the program. The former marks the test
as failing.
2025-04-06 03:49:15 -06:00
Behdad Esfahbod 163a66dc73 [test] Add test for aaa85931f3 2019-08-20 14:22:57 -07:00
Behdad Esfahbod 148d883680 [test] Don't call deprecated API 2019-05-13 14:34:53 -07:00
Behdad Esfahbod eb2be97f86 Port test off deprecated API 2018-10-09 07:48:52 -04:00
Behdad Esfahbod dcfcb950b8 [test] Fix -Wunused-parameter warnings 2018-09-30 18:14:50 +02:00
Ebrahim Byagowi f24b0b9728 Update the links and revive the dead ones 2018-04-12 13:44:32 +04:30
Behdad Esfahbod dd8598c1c7 [test] Pass closure to hb_font_set_glyph_func()
Exercises fix in c335fd7986
2016-02-25 11:20:05 +09:00
Behdad Esfahbod b3a2f6afba [test] Add test for cluster merging
Based on test from https://code.google.com/p/chromium/issues/detail?id=497578

Currently fails.  Basically, if there's a default_ignorable at the
start of text, and font has no space glyph, we remove the default_ignorable,
and that makes the first char in text to correspond to no cluster.

Fix coming.
2015-06-18 17:15:33 -07:00
Behdad Esfahbod 4d6dafd47f Rename test/ to test/api/ 2012-01-19 14:52:02 -05:00