Skip to content

Fix out-of-bounds reads in cmap format-12 and kern format-0 parsers#45

Open
ChakshuGupta13 wants to merge 1 commit into
tomolt:masterfrom
ChakshuGupta13:fix-cmap-kern-bounds
Open

Fix out-of-bounds reads in cmap format-12 and kern format-0 parsers#45
ChakshuGupta13 wants to merge 1 commit into
tomolt:masterfrom
ChakshuGupta13:fix-cmap-kern-bounds

Conversation

@ChakshuGupta13

Copy link
Copy Markdown

Closes #44.

Adds two missing bounds checks:

  1. cmap format-12/13 (cmap_fmt12_13): validates that the declared numGroups fits within the subtable len before the group-reading loop. Without this, a malformed font with numGroups larger than the actual subtable data causes reads past the font buffer. The existing cmap_fmt6 function already has the analogous check.

  2. kern format-0 (sft_kerning): validates that numPairs * 6 fits within the font before passing numPairs to bsearch.

Both checks use the already-validated subtable length (or is_safe_offset) to avoid integer overflow. No behavioral change for well-formed fonts.

Verified with AddressSanitizer: a crafted 178-byte PoC font that previously triggered a heap-buffer-overflow read now returns cleanly. Valid fonts (Ubuntu, FiraGO, Noto families) are unaffected.

Add missing validation that the declared entry count fits within the
subtable data for cmap format-12/13 (numGroups) and kern format-0
(numPairs). Without these checks, a malformed font can cause reads
past the end of the font buffer.

Both checks use the already-validated subtable length to avoid
integer overflow. No effect on well-formed fonts.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bounds checking improvements for cmap and kern table parsers

1 participant