Skip to content

Cannot produce outlines for TrueType fonts with 65536 glyphs #213

Closed

Description

@laurmaedje

For TrueType fonts with the maximum number of glyphs, the code below early returns because the range of u16 is exceeded, leading to loca table parsing failing:

let actual_total = match format {
IndexToLocationFormat::Short => data.len() / 2,
IndexToLocationFormat::Long => data.len() / 4,
};
let actual_total = u16::try_from(actual_total).ok()?;

This in turn means that no outlines can be produced.

Having the maximum number of glyphs is not that uncommon in CJK fonts, e.g. Source Han Sans or Noto Serif CJK.

Activity

  1. laurmaedje commented on Jun 4, 2026

    @laurmaedje
    ContributorAuthor

    In principle, this should not be that hard to fix because a usize (actual_total) is cast to a u16 just to be cast back to a usize in read_array. But I'm not sure what a clean fix would look like.

    I'm also not sure what the idea behind this is:

    // The number of ranges is `maxp.numGlyphs + 1`.
    //
    // Check for overflow first.
    let mut total = if number_of_glyphs.get() == u16::MAX {
    number_of_glyphs.get()
    } else {
    number_of_glyphs.get() + 1
    };

    if glyph_id == u16::MAX {
    return None;
    }

    At first glance, this seems like the last glyph simply cannot be outlined (which is better than no glyph being outlinable! but not ideal.)

  2. RazrFalcon commented on Jun 5, 2026

    @RazrFalcon
    Collaborator

    Ugh... so we have to switch u16 to u32 for count, slices, etc. That's would be a lot of work.

    I'm also not sure what the idea behind this is

    0xFFFF + 1 would overflow. That's what this check for. Overly verbose, sure, but still.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions