Sanitize Part II - #1943
Open
cmyr wants to merge 5 commits into
Open
Conversation
cmyr
force-pushed
the
sanitize-v3-fastread-on-unified
branch
from
June 23, 2026 20:06
c6ada7f to
9dc3f0e
Compare
cmyr
force-pushed
the
sanitize-v3-fastread-on-unified
branch
2 times, most recently
from
July 12, 2026 14:33
d32e523 to
de9c2ec
Compare
For sanitizable, non-generic tables, FontRead now validates by routing through the Sanitize trait: read_with_args calls read_checked, which runs sanitize and then constructs the table via read_fast. read_fast and read_checked are methods on Sanitize; there is no separate FastRead trait. read_fast is a required, unchecked constructor, and read_checked is the validate-then-construct entry point. SanitizeContext now carries two lifetimes (the data lifetime and the borrowed-state lifetime) so the data lifetime can be tied to the table's own lifetime, which is what lets generic offset types compose. Codegen emits read_fast for tables, format groups, and generic-group dispatchers.
This is used for resolving offsets that we know are sanitized. It uses the same return signature as we currently generate (Result<(),_>) in order to avoid breaking API everywhere, but the returned items are always present.
cmyr
force-pushed
the
sanitize-v3-fastread-on-unified
branch
from
August 7, 2026 09:13
de9c2ec to
4d4284e
Compare
read_fast now performs the same single MIN_SIZE bounds check that
FontRead did ('minimal validation'). The return type is Option<Self>,
returning `None` if the input data cannot be interpreted as the expected
table.
It is generally expected that fast_read is only used with sanitized
data, but with this change we are more defensive than we were in earlier
designs.
Callers that can't fail take the error: read_checked and fast_resolve
map None to ReadError::OutOfBounds.
Additionally this uses a macro for these very repetative constructors
that are just bounds-check + return self; this will eventually save us
~1500 loc across our generated files.
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.
based on #1934, this adds the 'fast reading' functionality. This is all still only for test tables; turning it on for real tables is in the next patch.