-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Protecting from stack overflow in recursive functions. #1488
Comments
https://crates.io/crates/stacker/ looks like something similar to what you're describing |
|
Yeah I agree with @jonas-schievink in that I think this should probably grow outside the standard library (perhaps on crates.io), and I think that the stacker crate provides a good way in for now! |
Late bloomer here. |
Neither rustc nor llvm currently guarantee any tail optimization, so writing a function that you think should be TCO often isn't |
Thank you, @tupshin |
Another late bloomer here. Is stacker the advised solution for now? Is TCO coming at some point? |
Not sure a separate crate is what you want here, because you could argue rust is memory unsafe if this is not protected against. |
Stack probes ensure that stack overflows do not ensure in memory safety
holes.
…On Mon, Oct 29, 2018, 06:40 Julian Ospald ***@***.***> wrote:
Not sure a separate crate is what you want here, because you could argue
rust is memory unsafe if this is not protected against.
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#1488 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AApc0svArTGXoELtv9P6Uel2t94RcLuBks5upobagaJpZM4HShTE>
.
|
For most functions, the stack depth can be structurally determined and therefore the Rust compiler could assert correctness. When the compiler can not know the stack depth required, a warning could be emitted. Additionally a decorator could be optionally added to a method to describe the expected stack depth max, and a runtime check be instrumented. |
I found several DoS attacks due to recursive functions in the past, so that's something I'm really interested in |
Suppose you have some recursive function:
It works for small values (that you need). But attacker can supply special unbalanced bad data that cause stack overflow. Getting rid of recursion requires big redesign and regretting about committing the "Let's use clever recursion here" idea. What if we can just add a direct protection against stack overlow?
Maybe functions for being aware of how much stack is still available should be a bit closer to language, so there can be
?
Alternative ideas:
try_recurse!(recursee(n))
that tries to check if there enough stack for calling and throws othewise;The text was updated successfully, but these errors were encountered: