Fix kern subsetting regression for fonts with >64KB kern tables - #11877
Open
wnvko-msft wants to merge 1 commit into
Open
Fix kern subsetting regression for fonts with >64KB kern tables#11877wnvko-msft wants to merge 1 commit into
wnvko-msft wants to merge 1 commit into
Conversation
Validate format 0 kern pair data against the uint32 kern table-directory length instead of the uint16 subtable length field, which wraps for subtables over 64KB and wrongly rejected valid fonts during XPS/PDF export and printing. Co-authored-by: Copilot
Contributor
There was a problem hiding this comment.
Pull request overview
This PR addresses a regression in the TrueType subsetter’s kern table handling that caused valid fonts with kern subtables larger than 64KB (where the subtable’s uint16 length wraps) to be rejected during XPS/PDF export and printing. The change updates the bounds validation for format 0 kern pair data to use the kern table-directory uint32 length instead of the wrapping uint16 subtable length.
Changes:
- Update
AdjustKernFormat0bounds validation to compare pair-array size againstTTTableLength(..., KERN_TAG)rather thanKernSubHeader.length. - Add an explanatory comment describing the
uint16wrap issue for large kern subtables.
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
miloush
approved these changes
Aug 28, 2026
pranav-gupta-msft
approved these changes
Aug 29, 2026
pranav-gupta-msft
approved these changes
Aug 29, 2026
subhajitm
approved these changes
Sep 4, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Validate format 0 kern pair data against the uint32 kern table-directory length instead of the uint16 subtable length field, which wraps for subtables over 64KB and wrongly rejected valid fonts during XPS/PDF export and printing.
Co-authored-by: Copilot
Fixes #11834 and #11836
Description
During font subsetting (XPS/print/PDF export),
AdjustKernFormat0validated the format 0 kern pair data against the kern subtablelengthheader field. Per the OpenTypekernspec that field is auint16, so for any kern subtable larger than 64KB it wraps to a value far smaller than the real size. The bounds check then sees the computed pair-array size exceed the wrapped length and rejects the font, failing the subset/export even though the font is valid.This change validates against the
uint32kern table-directory length (TTTableLength(pOutputBufferInfo, KERN_TAG)), which is a genuine 32-bit field that correctly describes tables over 64KB and was already validated against the buffer byCopyTableOverearlier in the same path.Customer Impact
Applications that print or export documents using common fonts with large kern tables (for example the Calibri family) fail during XPS/PDF export and printing. Some scenarios surface a
FileFormatException, and in certain apps the failure isunhandled and terminates the process. Without this fix, affected documents cannot be printed or exported without switching fonts or disabling the protection via the opt-out AppContext switch.
Regression
Yes. This is a regression introduced by the recent font-parsing hardening in the TrueType subsetter. Documents that previously printed/exported correctly began failing for fonts whose kern table exceeds 64KB.
Testing
Verified with a WPF app that exports every installed font to XPS:
Switch.MS.Internal.TtfDelta.DisableCmapAndSbitOverflowProtectionstill behaves as before (reverts to the pre-hardening code path).Risk
Low. The change is a single comparison - it swaps the wrapping
uint16subtable length for theuint32kern table-directory length that is already verified against the buffer earlier in the same code path. TheULongMult32overflow guard and all per-read/-write bounds checks (CheckInOffset/CheckOutOffset) are untouched, so the hardening remains fully in effect; the fix only stops valid large-kern fonts from being wrongly rejected.Microsoft Reviewers: Open in CodeFlow