Skip to content

Sanitize Part II - #1943

Open
cmyr wants to merge 5 commits into
sanitize-v3-on-unifiedfrom
sanitize-v3-fastread-on-unified
Open

Sanitize Part II#1943
cmyr wants to merge 5 commits into
sanitize-v3-on-unifiedfrom
sanitize-v3-fastread-on-unified

Conversation

@cmyr

@cmyr cmyr commented Jun 23, 2026

Copy link
Copy Markdown
Member

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.

@cmyr
cmyr force-pushed the sanitize-v3-fastread-on-unified branch from c6ada7f to 9dc3f0e Compare June 23, 2026 20:06
@cmyr cmyr changed the title Sanitize v3 fastread on unified Sanitize Part II Jun 23, 2026
@cmyr
cmyr force-pushed the sanitize-v3-fastread-on-unified branch 2 times, most recently from d32e523 to de9c2ec Compare July 12, 2026 14:33
cmyr added 4 commits August 7, 2026 05:12
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
cmyr force-pushed the sanitize-v3-fastread-on-unified branch from de9c2ec to 4d4284e Compare August 7, 2026 09:13
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.
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.

1 participant