Skip to content

fix: read_bytes debug_assert is reachable from malformed fonts #240

Closed

Description

@Goldziher

Filing what is left of #178 after the partial fix in the commit referenced below, so the remaining work is explicit.

Stream::read_bytes asserts:

// An integer overflow here on 32bit systems is almost guarantee to be caused
// by an incorrect parsing logic from the caller side.
// Simply using `checked_add` here would silently swallow errors, which is not what we want.
debug_assert!(self.offset as u64 + len as u64 <= u32::MAX as u64);

The intent is sound: catch caller logic errors loudly rather than silently returning None. The problem is that the assert cannot distinguish a caller bug from ordinary malformed input, and several callers pass a length derived from a raw font-controlled count.

read_array32 is now guarded (it checks the requested length against the remaining buffer before calling read_bytes), which covers the FeatureVariations path from #178 and the font-collection path from #127. Other callers computing a length from font data have not been audited.

This matters mainly for fuzzing: a debug_assert abort on malformed input is indistinguishable from a real finding, so it generates noise for anyone fuzzing a debug build, while release builds reject the same input cleanly.

Two options worth weighing:

  1. Audit every read_bytes caller that derives len from font data and bound it at the call site, keeping the assert as a genuine caller-bug tripwire.
  2. Replace the assert with a plain bounds check and accept that a caller bug returns None rather than aborting.

Option 1 preserves the original author's intent and is the safer default, but it needs the audit to be worth anything.

Activity

  1. added
    bug
    on Aug 5, 2026
  2. changed the title [-]read_bytes debug_assert is reachable from malformed fonts, not just caller bugs[/-] [+]fix: read_bytes debug_assert is reachable from malformed fonts[/+] on Aug 6, 2026
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

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions