Skip to content

fix: VariationTuple size assertion panics under -Zrandomize-layout #205

Closed

Description

@lovelymono

Same as rust-windowing/winit#4433.

You appear to be hitting a debug_assert in https://github.com/harfbuzz/ttf-parser. I suspect due to the nightly rustc version you're using increasing the size of the struct the assert runs on. You may wish to consider filing an issue there.

Description

Running a winit application fails with

thread 'main' (50531) panicked at /home/stella/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/ttf-parser-0.25.1/src/tables/gvar.rs:283:5:
assertion failed: core::mem::size_of::<VariationTuple>() <= 80

Platform details

Rust version:

rustc 1.93.0-nightly (646a3f8c1 2025-12-02)
cargo 1.93.0-nightly (2a7c49606 2025-11-25)

Operating system, windowing system:

NixOS, nixos-unstable github:NixOS/nixpkgs/2d293cbfa5a793b4c50d17c05ef9e385b90edf6c
GNOME 49, Wayland

Additional information

Output of RUST_BACKTRACE=full https://gist.github.com/lovelymono/92b8899270d610a25ef0e5378701924a.

Source code:

#[must_use]
fn real_main() -> iced::Result {
    iced::application("Howl", Howl::update, Howl::view).run()
}

fn main() -> std::process::ExitCode {
    match real_main() {
        Ok(()) => std::process::ExitCode::SUCCESS,
        Err(e) => {
            eprintln!("{e:?}");
            std::process::ExitCode::FAILURE
        },
    }
}

#[derive(Debug)]
enum Message {
}

#[derive(Default)]
struct Howl {}

impl Howl {
    fn update(&mut self, _: Message) {
        
    }

    fn view(&self) -> iced::Element<'_, Message> {
        "waow".into()
    }
}

Activity

  1. lovelymono commented on Dec 5, 2025

    @lovelymono
    Author

    Forgot to add, and it seems pretty relevant:

    I'm using:

    RUSTFLAGS=(
      "-Clink-arg=-fuse-ld=${nixos-unstable.lib.getExe pkgs.mold-wrapped}"
      "-Ctarget-cpu=native"
      "-Zunstable-options"
      "-Zrandomize-layout"
      "-Zthreads=8"
    )
    

    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.

    https://doc.rust-lang.org/stable/unstable-book/compiler-flags/randomize-layout.html

  2. RazrFalcon commented on Dec 5, 2025

    @RazrFalcon
    Collaborator

    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.

  3. lovelymono commented on Dec 6, 2025

    @lovelymono
    Author

    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.

  4. RazrFalcon commented on Dec 8, 2025

    @RazrFalcon
    Collaborator

    I understand. And if it would break in the future - we would fix it.

  5. Goldziher commented on Aug 6, 2026

    @Goldziher
    Collaborator

    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:

    seed before fb3eea1 after fb3eea1
    1 88 88
    2 96 96
    3 96 96
    4 80 80
    5 88 88

    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.

  6. added
    bug
    on Aug 6, 2026
  7. 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
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