You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix: read_bytes debug_assert is reachable from malformed fonts #240
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 asu64 + len asu64 <= u32::MAXasu64);
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:
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.
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.
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
Activity
[-]read_bytes debug_assert is reachable from malformed fonts, not just caller bugs[/-][+]fix: read_bytes debug_assert is reachable from malformed fonts[/+]