Commit Graph
16598 Commits
Author SHA1 Message Date
Behdad Esfahbod f222478bcc [wasm] Saturate Graphite positions
The standalone WebAssembly Graphite shaper mirrors the native backend
and had the same unchecked coordinate, cluster, and pen arithmetic.
Clamp backend values and saturate its signed position accumulation.

This is part of the complete position-overflow fix for issue #6151.

Testing: g++ -std=c++17 -Isrc -fsyntax-only src/wasm/graphite/shape.cc
Testing: meson test -C build --print-errorlogs

Assisted-by: Codex <codex@openai.com>
2026-08-12 18:27:23 -06:00
Behdad Esfahbod 3385a2deb0 [subset] Saturate instantiated metrics
CFF2 instancing consumes full-range glyph extents and untrusted
variation deltas while rebuilding font and glyph metrics. Saturate
extent endpoints and side-bearing differences and keep advance
accumulation widened through its final UFWORD clamp.

This is part of the complete position-overflow fix for issue #6151.

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

Assisted-by: Codex <codex@openai.com>
2026-08-12 18:26:14 -06:00
Behdad Esfahbod 7ea48552e3 [math] Compare full-range kern positions safely
The MATH kern search comparator multiplied and subtracted signed
positions, which overflows for full-range correction heights. Compare
the values directly while respecting the scale direction.

This is part of the complete position-overflow fix for issue #6151.

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

Assisted-by: Codex <codex@openai.com>
2026-08-12 18:25:03 -06:00
Behdad Esfahbod 885716c955 [fontations] Saturate font positions
The Fontations callbacks used ordinary Rust arithmetic for vertical
metrics and glyph extents. Use saturating operations for sequential
updates and widened arithmetic for the multi-term vertical-origin
fallback.

This is part of the complete position-overflow fix for issue #6151.

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

Assisted-by: Codex <codex@openai.com>
2026-08-12 18:23:02 -06:00
Behdad Esfahbod 974025fe23 [metrics] Saturate fallback metrics
Fallback cap-height and em-size formulas multiply or combine
full-range glyph positions and font scales. Widen and clamp those
formulas and saturate the underline-offset negation.

This is part of the complete position-overflow fix for issue #6151.

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

Assisted-by: Codex <codex@openai.com>
2026-08-12 18:21:11 -06:00
Behdad Esfahbod 99fcf732cb [outline] Clamp glyph extents
Variable glyf and CFF outlines can produce floating bounds outside the
signed position range. Keep rounded endpoints widened, clamp bearings,
and clamp endpoint differences before scaling the glyph extents.

This is part of the complete position-overflow fix for issue #6151.

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

Assisted-by: Codex <codex@openai.com>
2026-08-12 18:20:20 -06:00
Behdad Esfahbod 0855a58fdf [bitmap] Clamp scaled glyph extents
Bitmap strike scaling converts attacker-controlled image dimensions and
offsets to glyph positions through unchecked float and mixed-sign
arithmetic. Widen the sbix coordinate sum and clamp scaled sbix and
CBDT extents.

This is part of the complete position-overflow fix for issue #6151.

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

Assisted-by: Codex <codex@openai.com>
2026-08-12 18:17:37 -06:00
Behdad Esfahbod f65eab255c [cairo] Widen glyph position accumulation
The Cairo adapter accumulated full-range glyph positions in signed
HarfBuzz positions before converting them to doubles. Accumulate and
negate in double precision instead, and clamp the scale passed back to
the HarfBuzz font.

This is part of the complete position-overflow fix for issue #6151.

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

Assisted-by: Codex <codex@openai.com>
2026-08-12 18:16:08 -06:00
Behdad Esfahbod 210e97d64f [buffer] Saturate serialized positions
Buffer serialization accumulates advances and adds offsets in signed
positions even when advances are omitted from the output. Saturate the
pen and final-coordinate arithmetic in both text and JSON formats.

This is part of the complete position-overflow fix for issue #6151.

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

Assisted-by: Codex <codex@openai.com>
2026-08-12 18:14:57 -06:00
Behdad Esfahbod a2206577f1 [ft] Clamp font positions
FreeType exposes full-width fixed-point metrics which were narrowed or
combined before reaching HarfBuzz positions. Widen the calculations,
clamp advances, origins, kerning, extents, and font metrics, and avoid
negating the minimum fixed-point value.

This is part of the complete position-overflow fix for issue #6151.

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

Assisted-by: Codex <codex@openai.com>
2026-08-12 18:13:54 -06:00
Behdad Esfahbod 1f1a2217ea [ot-font] Saturate vertical origins
Vertical-origin caching normalizes positions by scale sign, and the
extents fallback combines several full-width metrics. Saturate sign and
font-advance operations and widen the fallback centering formula.

This is part of the complete position-overflow fix for issue #6151.

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

Assisted-by: Codex <codex@openai.com>
2026-08-12 18:11:40 -06:00
Behdad Esfahbod 507b52e088 [ot-font] Saturate glyph advances
OpenType fallback and variable advances can span the full position
range, while non-variable table values are unsigned. Clamp unscaled
values, use the full-range scalers, and saturate vertical negation and
font-extents subtraction.

This is part of the complete position-overflow fix for issue #6151.

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

Assisted-by: Codex <codex@openai.com>
2026-08-12 18:10:26 -06:00
Behdad Esfahbod 695d3afaa9 [font] Scale full-range font positions
Some variable-font and backend metrics are already full-width signed
positions rather than 16-bit font values. Add explicit full-range
scalers which preserve the fixed-point fast path for ordinary values
and clamp wider results through the existing floating scaler.

This is part of the complete position-overflow fix for issue #6151.

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

Assisted-by: Codex <codex@openai.com>
2026-08-12 18:09:32 -06:00
Behdad Esfahbod 9d1db8c527 [uniscribe] Clamp shaped positions
Uniscribe scales scratch advances and offsets through unchecked
floating-point-to-position conversions. Clamp each result and negate
backward offsets after widening them to double.

This is part of the complete position-overflow fix for issue #6151.

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

Assisted-by: Codex <codex@openai.com>
2026-08-12 18:07:09 -06:00
Behdad Esfahbod 8c67f8315b [directwrite] Clamp shaped positions
DirectWrite returns floating-point advances and offsets which were
stored and scaled through unchecked integer conversions. Clamp the
scratch values and final scaled positions, and negate RTL offsets in
floating point.

This is part of the complete position-overflow fix for issue #6151.

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

Assisted-by: Codex <codex@openai.com>
2026-08-12 18:06:27 -06:00
Behdad Esfahbod 695ff500b3 [directwrite] Saturate font positions
DirectWrite metrics are wider than the signed 16-bit values accepted by
the normal font-space scaler, and extents combine mixed signed and
unsigned fields. Preserve the common scaling path, clamp wider values,
and saturate the resulting extents arithmetic.

This is part of the complete position-overflow fix for issue #6151.

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

Assisted-by: Codex <codex@openai.com>
2026-08-12 18:05:40 -06:00
Behdad Esfahbod 3a03c500e9 [coretext] Clamp font positions
CoreText font callbacks convert floating-point advances, origins,
extents, and metrics directly to signed positions. Clamp conversions,
widen extents arithmetic, and avoid negating an integer scale first.

This is part of the complete position-overflow fix for issue #6151.

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

Assisted-by: Codex <codex@openai.com>
2026-08-12 18:03:48 -06:00
Behdad Esfahbod 4938c3a083 [coretext] Saturate shaped positions
CoreText shaping converts unbounded floating-point run positions and
font callback results to signed glyph positions. Clamp those
conversions and saturate fallback advance and origin arithmetic.

This is part of the complete position-overflow fix for issue #6151.

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

Assisted-by: Codex <codex@openai.com>
2026-08-12 18:03:00 -06:00
Behdad Esfahbod 2e2a77a60f [graphite2] Saturate shaped positions
Graphite coordinates and cluster advances can exceed the position
range after scaling or accumulation. Clamp backend-produced values and
saturate cluster and pen arithmetic before storing glyph positions.

This is part of the complete position-overflow fix for issue #6151.

Testing: ninja -C build-graphite2 src/libharfbuzz.so.0.61431.0
Testing: meson test -C build --print-errorlogs

Assisted-by: Codex <codex@openai.com>
2026-08-12 18:01:41 -06:00
Behdad Esfahbod 2a2a3792a5 [font] Clamp scaled glyph extents
Glyph extents can span the full position range supplied by a callback.
Scale widened rectangle endpoints and clamp the rounded result instead
of narrowing inputs and relying on overflowing position arithmetic.

This is part of the complete position-overflow fix for issue #6151.

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

Assisted-by: Codex <codex@openai.com>
2026-08-12 17:58:38 -06:00
Behdad Esfahbod 160179e64f [font] Saturate synthetic font extents
Synthetic emboldening updates callback-provided font extents with
unchecked position arithmetic. Saturate the sign adjustment and each
extents update.

This is part of the complete position-overflow fix for issue #6151.

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

Assisted-by: Codex <codex@openai.com>
2026-08-12 17:56:46 -06:00
Behdad Esfahbod f0e44cfda7 [font] Saturate synthetic glyph extents
Synthetic slanting and emboldening update callback-provided glyph
extents with unchecked position arithmetic. Widen and clamp the slant
geometry, then saturate sequential emboldening updates.

This is part of the complete position-overflow fix for issue #6151.

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

Assisted-by: Codex <codex@openai.com>
2026-08-12 17:55:04 -06:00
Behdad Esfahbod b2bd10211d [kerx] Saturate attachment coordinates
AAT kerx format 4 derives mark offsets by subtracting callback or scaled
anchor coordinates. Saturate each coordinate difference so extreme
origins and public font scales cannot overflow.

This is part of the complete position-overflow fix for issue #6151.

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

Assisted-by: Codex <codex@openai.com>
2026-08-12 17:51:21 -06:00
Behdad Esfahbod d8927d1b18 [GPOS] Saturate split pair positioning
The optional split-kern path applies a ValueRecord to a temporary
position and redistributes it across the pair. Saturate every destination
update and clamp the one three-term expression after widening.

This closes the final unchecked GPOS position path for issue #6151.

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

Assisted-by: Codex <codex@openai.com>
2026-08-12 17:50:24 -06:00
Behdad Esfahbod eb4e60290f [font] Saturate fallback origin conversion
Bulk origin fallback converts between horizontal and vertical origins
by adding advances and ascenders. Saturate those temporary position
updates before applying them to the buffer.

This is part of the complete position-overflow fix for issue #6151.

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

Assisted-by: Codex <codex@openai.com>
2026-08-12 17:48:20 -06:00
Behdad Esfahbod 5528a71752 [font] Saturate synthetic glyph metrics
Synthetic emboldening updates callback-provided glyph advances and
origins. Saturate scalar and bulk results, including strength negation
for negative font scales.

This keeps public callback extremes from reintroducing position overflow
as part of the complete fix for issue #6151.

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

Assisted-by: Codex <codex@openai.com>
2026-08-12 17:46:57 -06:00
Behdad Esfahbod 05d7cb5fec [font] Clamp synthetic emboldening strength
Computing synthetic emboldening strength could negate INT_MIN through
abs() and convert an out-of-range float to int32_t. Use floating-point
absolute value and clamp the rounded result to a valid position.

This is part of the complete position-overflow fix for issue #6151.

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

Assisted-by: Codex <codex@openai.com>
2026-08-12 17:45:00 -06:00
Behdad Esfahbod 4c8467e823 [font] Clamp scaled positions
Font scaling can produce values outside hb_position_t at extreme public
font scales. Clamp design-unit, floating-point, and parent-font scaling
results before returning them to positioning code.

This ensures later saturating additions receive valid position operands
as part of the complete fix for issue #6151.

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

Assisted-by: Codex <codex@openai.com>
2026-08-12 17:43:34 -06:00
Behdad Esfahbod ed76b12fc1 [arabic] Saturate stch justification positions
Arabic stch justification accumulates word and tile widths, then walks
repeated tiles to assign offsets. Saturate those hb_position_t values
and clamp the computed overlap from its 64-bit intermediate.

This is part of the complete position-overflow fix for issue #6151.

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

Assisted-by: Codex <codex@openai.com>
2026-08-12 17:41:40 -06:00
Behdad Esfahbod 9e37c4a7e8 [fallback] Saturate fallback cluster positions
Fallback cluster positioning accumulates advances into mark offsets and
partitions ligature extents. Saturate the position accumulators and use
bounded 64-bit intermediates for the component formulas.

This completes the tracked fallback-shaping arithmetic covered by
Chromium's sanitizer exemption for issue #6151.

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

Assisted-by: Codex <codex@openai.com>
2026-08-12 17:40:33 -06:00
Behdad Esfahbod 794eb3e7b3 [fallback] Saturate fallback mark placement
Fallback mark positioning combines several glyph extents and updates a
running attachment box. Use widened, clamped formulas where cancellation
matters and saturating arithmetic for sequential box updates.

Keep the original integer-division rounding behavior. This fixes the
remaining arithmetic in Chromium's fallback sanitizer exemption as
part of issue #6151.

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

Assisted-by: Codex <codex@openai.com>
2026-08-12 17:39:25 -06:00
Behdad Esfahbod 8ff823adce [algs] Add a signed integer clamp helper
Provide an always-inline int64_t overload of hb_clamp_to for cold
position formulas that need wider intermediate arithmetic while
preserving integer division and rounding semantics.

Add boundary tests. This supports the complete position-overflow fix
for issue #6151.

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

Assisted-by: Codex <codex@openai.com>
2026-08-12 17:38:49 -06:00
Behdad Esfahbod 3c5af5f416 [fallback] Saturate zeroed mark offsets
Fallback mark positioning can preserve placement while zeroing mark
advances. Saturate that offset adjustment instead of subtracting
unchecked hb_position_t values.

This is part of the complete position-overflow fix for issue #6151.

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

Assisted-by: Codex <codex@openai.com>
2026-08-12 17:35:37 -06:00
Behdad Esfahbod aa749a84ba [font] Saturate origin offset helpers
Font-origin fallback code centralizes position updates in add, subtract,
and signed offset helpers. Make those helpers saturating, including the
INT_MIN case that previously overflowed while multiplying by -1.

This is part of the complete position-overflow fix for issue #6151.

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

Assisted-by: Codex <codex@openai.com>
2026-08-12 17:34:39 -06:00
Behdad Esfahbod fd193a9649 [ot] Saturate mark offset adjustment
Zeroing mark widths first moves their advances into the offsets. Use
saturating subtraction for that position update so extreme font scales
cannot overflow before GPOS is applied.

This is part of the complete position-overflow fix for issue #6151.

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

Assisted-by: Codex <codex@openai.com>
2026-08-12 17:33:01 -06:00
Behdad Esfahbod c5497821f7 [buffer] Saturate glyph normalization positions
Glyph normalization accumulates cluster advances, moves offsets, and
then redistributes the result after sorting. Saturate each hb_position_t
update so very large clusters cannot overflow during normalization.

This is part of the complete position-overflow fix for issue #6151.

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

Assisted-by: Codex <codex@openai.com>
2026-08-12 17:32:30 -06:00
Behdad Esfahbod 91b07e93d4 [trak] Saturate tracking advances
AAT tracking adds the selected tracking value to the first glyph of
each grapheme. Saturate horizontal and vertical advance updates so an
extreme scale or repeated application cannot overflow hb_position_t.

This is part of the complete position-overflow fix for issue #6151.

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

Assisted-by: Codex <codex@openai.com>
2026-08-12 17:31:45 -06:00
Behdad Esfahbod d9bd6e9895 [kerx] Saturate state-machine positions
AAT kerx state-machine actions add scaled values to glyph advances and
offsets, including cross-stream attachments. Saturate each stored
position update to avoid signed overflow on repeated actions.

This is part of the complete position-overflow fix for issue #6151.

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

Assisted-by: Codex <codex@openai.com>
2026-08-12 17:31:02 -06:00
Behdad Esfahbod cacd892a0b [kern] Saturate legacy kerning positions
Legacy kern application split a kerning value across two glyphs with
unchecked additions to advances and offsets. Saturate those updates and
remove the signed-overflow sanitizer exemption from the function.

The exemption macro has no remaining tracked users, so remove it as
well. This is part of the complete fix for issue #6151.

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

Assisted-by: Codex <codex@openai.com>
2026-08-12 17:29:53 -06:00
Behdad Esfahbod d9a68e313e [GPOS] Clamp synthetic slant offsets
Applying a synthetic slant combines a floating-point displacement with
an existing hb_position_t offset. Clamp the final result so extreme
slants cannot overflow the float-to-integer conversion or the position
sum.

This is part of the complete position-overflow fix for issue #6151.

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

Assisted-by: Codex <codex@openai.com>
2026-08-12 17:27:56 -06:00
Behdad Esfahbod fe3ab6b239 [GPOS] Saturate cursive positioning
Cursive attachment combines rounded anchors with existing advances and
offsets, then may negate the cross-stream displacement. Clamp the
floating-point conversions and saturate the integer arithmetic at each
stored hb_position_t result.

This is part of the complete position-overflow fix for issue #6151.

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

Assisted-by: Codex <codex@openai.com>
2026-08-12 17:25:57 -06:00
Behdad Esfahbod e177de31b0 [GPOS] Saturate reversed cursive offsets
Reversing a cursive attachment chain negates the child's cross-stream
offset. Saturate that negation so INT_MIN produces INT_MAX instead of
signed-overflow undefined behavior.

This is part of the complete position-overflow fix for issue #6151.

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

Assisted-by: Codex <codex@openai.com>
2026-08-12 17:24:22 -06:00
Behdad Esfahbod 291b7ef1e0 [algs] Complete signed saturation helpers
Add an always-inline saturating negation for position values that can
reach INT_MIN. Also require the floating-point clamp helper to inline,
matching the add and subtract helpers used throughout shaping.

Extend the boundary tests for both helpers. This supports the complete
position-overflow fix for issue #6151.

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

Assisted-by: Codex <codex@openai.com>
2026-08-12 17:23:05 -06:00
Behdad Esfahbod f57cc31a02 [GPOS] Saturate ValueRecord application
ValueRecord placement, advance, and device adjustments all update
hb_position_t fields. Saturate those additions and subtractions so
large scales or repeated lookups cannot invoke signed overflow.

The helper keeps the common path to one arithmetic instruction and a
not-taken overflow branch, which limits the cost in this hot path.
This is part of the complete fix for issue #6151.

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

Assisted-by: Codex <codex@openai.com>
2026-08-12 17:20:50 -06:00
Behdad Esfahbod d36a16f8ca [GPOS] Saturate propagated attachment offsets
Deferred mark and cursive attachment propagation combines offsets with
the advances between attached glyphs. Use saturating arithmetic for
each position update instead of relying on signed overflow behavior.

This removes the historical overflow from the function that issue
#6151 moved out of Chromium's sanitizer exemption.

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

Assisted-by: Codex <codex@openai.com>
2026-08-12 17:19:26 -06:00
Behdad Esfahbod bcce9d4f55 [GPOS] Saturate resolved cursive offsets
A mark can resolve its cross-stream position through a cursive
attachment chain. Saturate that accumulation so an overlong chain
cannot overflow hb_position_t while applying GPOS.

This is part of the position-overflow fix for issue #6151.

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

Assisted-by: Codex <codex@openai.com>
2026-08-12 17:18:11 -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 764d42cc64 [algs] Add fast signed saturating arithmetic
Provide always-inline signed add and subtract helpers for position
arithmetic. Compiler overflow builtins reduce the common path to one
arithmetic instruction and a not-taken overflow branch.

This is the foundation for fixing the position overflow reported in
issue #6151.

Assisted-by: Codex <codex@openai.com>
2026-08-12 17:12:35 -06:00
Khaled Hosny ab5ecbb839 14.3.1 2026-08-13 01:49:23 +03:00
Behdad Esfahbod d8dabe2594 [subset] Keep glyf table alive during serialization (#6150)
SubsetGlyph stores borrowed slices into the source glyf table.  Faces
created with a table callback may return a fresh blob on each request,
so destroying the population accelerator left those slices dangling
before they were serialized.

Retain the exact glyf blob through serialization.  Exercise this path
by making the existing create-for-tables test return copied blobs.

Reported by WinD39 - Huynh Dinh Vu.

Fixes: https://issues.chromium.org/issues/536584255
Assisted-by: OpenAI Codex <codex@openai.com>
2026-08-11 17:40:40 -06:00