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: VariationTuple size assertion panics under -Zrandomize-layout #205
and -Zrandomize-layout probably causes this issue (as expected, which is its purpose.) VariationTuple should probably use #[repr(C)] to guarantee the struct layout and size.
I would say this is out of scope. There are no plans to support -Zrandomize-layout.
And yes, some parts of ttf-parser are very sensitive to the struct sizes.
I think you misunderstand what -Zrandomize-layout does: it emulates some part of what Rust compiler is allowed to do anyway.
The -Zrandomize-layout flag changes the layout algorithm for repr(Rust) types defined in the current crate from its normal optimization goals to pseudorandomly rearranging fields within the degrees of freedom provided by the largely unspecified default representation. This also affects type sizes and padding.
There is no guarantee that a future version of rustc isn't going to rearrange the fields (for example, for optimization purposes) and break this code the same way.
I attempted a fix for this in fb3eea1 by putting #[repr(C)] on VariationTuple. That commit does not work, and I am reverting it. Measuring it rather than assuming is what caught this, so here are the numbers.
#[repr(C)] on VariationTuple pins the order of its three fields, but it does not propagate into their types. SetPointsIter, PackedPointsIter, PackedDeltasIter, RunState and PointAndDelta all stay repr(Rust), and those are exactly what -Zrandomize-layout reorders. Since VariationTuple's size is essentially the sum of the nested sizes, pinning only the outer struct changes nothing.
Sizes under -Zrandomize-layout, comparing the commit before the fix against the commit after it:
Byte-identical on every seed. The growth is in the nested types — PackedPointsIter 24 to 32, PackedDeltasIter 32 to 40, PointAndDelta 12 to 16 — which the outer repr(C) cannot reach. Under default layout the total is exactly 80, sitting precisely on the limit, which is why any reordering at all pushes it over.
The original panic still reproduces on current main: outlining every glyph of SourceSansVariable-Roman.ttf with all axes at midpoint, debug build, seeds 1-5, all five panic at src/tables/gvar.rs:287 with the exact message in your report.
Two things worth recording for whoever picks this up:
It is debug-only. The guard is a debug_assert!, so release builds skip it entirely. That is not a reprieve — it means that in release the stack-budget invariant the assertion exists to enforce is simply unchecked, and the larger tuples get used anyway.
It is 64-bit-only. Several fields hold &[u8], a fat pointer, so on a 32-bit target the tuple computes to roughly 56 bytes and has ample headroom. The problem is concentrated on 64-bit, which matches your platform.
A real fix means #[repr(C)] on every type reachable from VariationTuple, not just the outer one. Before doing that, I would rather settle the question @RazrFalcon raised: the assertion enforces a stack budget, not soundness, and -Zrandomize-layout is a nightly flag whose entire purpose is to break layout assumptions. Nothing here is unsound under randomization — the parser just uses more stack than the internal budget claims. So relaxing the assertion may be the more honest fix than chasing repr(C) through five types to defend a number that is only meaningful under default layout.
Leaving this open with the evidence rather than closing it behind a change that measurably does nothing.
changed the title [-]Panics with `assertion failed: core::mem::size_of::<VariationTuple>() <= 80`[/-][+]fix: VariationTuple size assertion panics under -Zrandomize-layout[/+]on Aug 6, 2026
Activity
lovelymono commentedon Dec 5, 2025
Forgot to add, and it seems pretty relevant:
I'm using:
and
-Zrandomize-layoutprobably causes this issue (as expected, which is its purpose.)VariationTupleshould probably use#[repr(C)]to guarantee the struct layout and size.https://doc.rust-lang.org/stable/unstable-book/compiler-flags/randomize-layout.html
RazrFalcon commentedon Dec 5, 2025
I would say this is out of scope. There are no plans to support
-Zrandomize-layout.And yes, some parts of
ttf-parserare very sensitive to the struct sizes.lovelymono commentedon Dec 6, 2025
I think you misunderstand what
-Zrandomize-layoutdoes: it emulates some part of what Rust compiler is allowed to do anyway.There is no guarantee that a future version of rustc isn't going to rearrange the fields (for example, for optimization purposes) and break this code the same way.
RazrFalcon commentedon Dec 8, 2025
I understand. And if it would break in the future - we would fix it.
Goldziher commentedon Aug 6, 2026
I attempted a fix for this in fb3eea1 by putting
#[repr(C)]onVariationTuple. That commit does not work, and I am reverting it. Measuring it rather than assuming is what caught this, so here are the numbers.#[repr(C)]onVariationTuplepins the order of its three fields, but it does not propagate into their types.SetPointsIter,PackedPointsIter,PackedDeltasIter,RunStateandPointAndDeltaall stayrepr(Rust), and those are exactly what-Zrandomize-layoutreorders. SinceVariationTuple's size is essentially the sum of the nested sizes, pinning only the outer struct changes nothing.Sizes under
-Zrandomize-layout, comparing the commit before the fix against the commit after it:Byte-identical on every seed. The growth is in the nested types —
PackedPointsIter24 to 32,PackedDeltasIter32 to 40,PointAndDelta12 to 16 — which the outerrepr(C)cannot reach. Under default layout the total is exactly 80, sitting precisely on the limit, which is why any reordering at all pushes it over.The original panic still reproduces on current
main: outlining every glyph ofSourceSansVariable-Roman.ttfwith all axes at midpoint, debug build, seeds 1-5, all five panic atsrc/tables/gvar.rs:287with the exact message in your report.Two things worth recording for whoever picks this up:
It is debug-only. The guard is a
debug_assert!, so release builds skip it entirely. That is not a reprieve — it means that in release the stack-budget invariant the assertion exists to enforce is simply unchecked, and the larger tuples get used anyway.It is 64-bit-only. Several fields hold
&[u8], a fat pointer, so on a 32-bit target the tuple computes to roughly 56 bytes and has ample headroom. The problem is concentrated on 64-bit, which matches your platform.A real fix means
#[repr(C)]on every type reachable fromVariationTuple, not just the outer one. Before doing that, I would rather settle the question @RazrFalcon raised: the assertion enforces a stack budget, not soundness, and-Zrandomize-layoutis a nightly flag whose entire purpose is to break layout assumptions. Nothing here is unsound under randomization — the parser just uses more stack than the internal budget claims. So relaxing the assertion may be the more honest fix than chasingrepr(C)through five types to defend a number that is only meaningful under default layout.Leaving this open with the evidence rather than closing it behind a change that measurably does nothing.
Revert "fix: pin VariationTuple layout with repr(C)"
[-]Panics with `assertion failed: core::mem::size_of::<VariationTuple>() <= 80`[/-][+]fix: VariationTuple size assertion panics under -Zrandomize-layout[/+]