Skip to content

fix: Guard SizeSkeleton::compute against stack overflow#156235

Open
rajgandhi1 wants to merge 3 commits intorust-lang:mainfrom
rajgandhi1:compiler_stack_overflow_fix
Open

fix: Guard SizeSkeleton::compute against stack overflow#156235
rajgandhi1 wants to merge 3 commits intorust-lang:mainfrom
rajgandhi1:compiler_stack_overflow_fix

Conversation

@rajgandhi1
Copy link
Copy Markdown

Fixes #156137

Fix: extract the recursion into a private compute_inner that carries a depth counter. When depth exceeds the crate's recursion limit, return LayoutError::Unknown and let the existing transmute size-check produce a normal error instead of crashing.

A regression test is included in tests/ui/transmute/.

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels May 6, 2026
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented May 6, 2026

r? @adwinwhite

rustbot has assigned @adwinwhite.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: compiler, types
  • compiler, types expanded to 73 candidates
  • Random selection from 20 candidates

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

// Bail out if we've recursed too deeply (issue #156137); a cyclic type
// alias can otherwise blow the stack here.
if !tcx.recursion_limit().value_within_limit(depth) {
return Err(tcx.arena.alloc(LayoutError::Unknown(ty)));
Copy link
Copy Markdown
Contributor

@oli-obk oli-obk May 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should just raise a recursion limit error here. There's a function for doing that, several other recursion limit checks should be doing that, too.

View changes since the review

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you mean the emit_err(RecursionLimitReached{...}) pattern used in struct_tail_raw?

but SizeSkeleton::compute has no span. should I add it and create RecursionLimitReachedSizeSkeleton diagnostic in error.rs?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Transmuting struct that contains itself causes compiler stack overflow

5 participants