-
Notifications
You must be signed in to change notification settings - Fork 12.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Call stack exhaustion (overflow) in parser with a very large generated file #128422
Comments
Note that As a practical matter, this currently makes it impossible for developers on illumos to make a Rust build natively, or even run commands like (To unblock myself, I built rustc targeting illumos from Linux, with this patch applied. This worked.) |
That PR is rust-lang/stacker#88. |
The file doesn't need to be very big to crash the compiler. Here is the smallest file that crashes rustc on my computer; it's 12Kb bad.zip
In a similar situation, Clang generates a nice message pointing to the error in the input file:
|
Code
Can't provide a minimal example for obvious reasons :)
On my Linux x86_64 system this deterministically crashes in the rustc parser due to call stack exhaustion (i.e. a call stack overflow). The full output is here. (Note I haven't built a Rust compiler with symbols, because I have enough information to establish the cause without needing symbols.)
The file that's failing to parse is this one. It is an autogenerated file called
isle_opt.rs
, and is generated by thecranelift-codegen
build script.This also reproduces with
rustc 1.82.0-nightly (f8060d282 2024-07-30)
.What's the
RUST_MIN_STACK
doing, you might ask? Well, long story behind this, but I got here by first diagnosing the issue on illumos, which crashed in the same spot with the same crate (illumos stack trace), without requiringRUST_MIN_STACK
to be set.RUST_MIN_STACK
is set to 1MiB, 2MiB (default) or 4MiB. This is consistent with the description below.What's happening is:
cranelift-codegen
is triggering the crash by requiring more than 1MiB of stack space.rustc
parser running againstcranelift-codegen
needs more than 1MiB of stack space, but less than 2MiB.rustc
requests a 1MiB stack segment with a 100KiB red zone.stacker
can see that well over 100KiB of stack space is left, and so it does not allocate a new segment.stacker
cannot see how much stack was left, and so it unconditionally allocates a new 1MiB segment.isle_opt.rs
.With
RUST_MIN_STACK
used to set a stack size <= 1MiB, we would expect that:rustc
callsstacker
as before.stacker
decides there is enough stack space and doesn't create a new segment, or it decides there isn't enough and does create a new 1MiB segment.cranelift-codegen
, and the program crashes.To the best of my understanding, this is a bug in rustc's use of stacker. The fact that 1MiB just isn't enough to parse that file was being masked by the default stack size of 2MiB.
I think the fix is that
rustc
should be callingstacker
more often in its recursive sections -- if it did, then stacker would allocate a new segment as soon as less than 100KiB of stack space was available.(A secondary issue is that stacker should be able to detect stack sizes on illumos -- I'll try sending a PR for that separately.)
Meta
Reproes with both:
rustc --version --verbose
:and
Error output
https://gist.github.com/sunshowers/3ac000e5a5022acd3f07886a16a39520
The text was updated successfully, but these errors were encountered: