adambratschikaye opened PR #12542 from adambratschikaye:abk/limit-backtrace-size to bytecodealliance:main:
Add
Config::wasm_backtrace_max_framesoption to limit the number of frames collected in backtraces and set the default at 20. This helps prevent expensive work from very deep call stacks.Setting the value to 0 is the same as disabling backtraces and so this change deprecates
Config::wasm_backtrace.Addresses https://github.com/bytecodealliance/wasmtime/issues/5052
<!--
Please make sure you include the following information:
If this work has been discussed elsewhere, please include a link to that
conversation. If it was discussed in an issue, just mention "issue #...".Explain why this change is needed. If the details are in an issue already,
this can be brief.Our development process is documented in the Wasmtime book:
https://docs.wasmtime.dev/contributing-development-process.htmlPlease ensure all communication follows the code of conduct:
https://github.com/bytecodealliance/wasmtime/blob/main/CODE_OF_CONDUCT.md
-->
adambratschikaye requested fitzgen for a review on PR #12542.
adambratschikaye requested wasmtime-core-reviewers for a review on PR #12542.
github-actions[bot] added the label wasmtime:config on PR #12542.
github-actions[bot] added the label wasmtime:api on PR #12542.
fitzgen submitted PR review:
Thanks! A couple nitpicks inline below before we merge this.
fitzgen created PR review comment:
(Also, we could avoid the
NonZeroUsize::new(...).unwrap()noise here by making theDEFAULT_WASM_BACKTRACE_MAX_FRAMESconstant be aNonZeroUsizealready.)
fitzgen created PR review comment:
Can we represent this as an
Option<NonZeroUsize>? That will make use sites clearer, rather than checking for zero.
fitzgen created PR review comment:
Minor nitpick, but I think the logic is a little more clear when collapsing the nested conditionals into a single
match:match (enable, self.wasm_backtrace_max_frames) { (false, _) => self.wasm_backtrace_max_frames = None, // Wasm backtraces were disabled; enable them with the // default maximum number of frames to capture. (true, None) => self.wasm_backtrace_max_frames = { Some(NonZeroUsize::new(DEFAULT_WASM_BACKTRACE_MAX_FRAMES).unwrap()); } // Wasm backtraces are already enabled; keep the existing // max-frames configuration. (true, Some(_)) => {} }
github-actions[bot] commented on PR #12542:
Label Messager: wasmtime:config
It looks like you are changing Wasmtime's configuration options. Make sure to
complete this check list:
[ ] If you added a new
Configmethod, you wrote extensive documentation for
it.<details>
Our documentation should be of the following form:
```text
Short, simple summary sentence.More details. These details can be multiple paragraphs. There should be
information about not just the method, but its parameters and results as
well.Is this method fallible? If so, when can it return an error?
Can this method panic? If so, when does it panic?
Example
Optional example here.
```</details>
[ ] If you added a new
Configmethod, or modified an existing one, you
ensured that this configuration is exercised by the fuzz targets.<details>
For example, if you expose a new strategy for allocating the next instance
slot inside the pooling allocator, you should ensure that at least one of our
fuzz targets exercises that new strategy.Often, all that is required of you is to ensure that there is a knob for this
configuration option in [wasmtime_fuzzing::Config][fuzzing-config] (or one
of its nestedstructs).Rarely, this may require authoring a new fuzz target to specifically test this
configuration. See [our docs on fuzzing][fuzzing-docs] for more details.</details>
[ ] If you are enabling a configuration option by default, make sure that it
has been fuzzed for at least two weeks before turning it on by default.[fuzzing-config]: https://github.com/bytecodealliance/wasmtime/blob/ca0e8d0a1d8cefc0496dba2f77a670571d8fdcab/crates/fuzzing/src/generators.rs#L182-L194
[fuzzing-docs]: https://docs.wasmtime.dev/contributing-fuzzing.html
<details>
To modify this label's message, edit the <code>.github/label-messager/wasmtime-config.md</code> file.
To add new label messages or remove existing label messages, edit the
<code>.github/label-messager.json</code> configuration file.</details>
venkkatesh-sekar submitted PR review.
venkkatesh-sekar created PR review comment:
let mut wasm_trace = Vec::<FrameInfo>::with_capacity(max_frames);
adambratschikaye updated PR #12542.
adambratschikaye updated PR #12542.
adambratschikaye updated PR #12542.
adambratschikaye requested fitzgen for a review on PR #12542.
adambratschikaye requested venkkatesh-sekar for a review on PR #12542.
adambratschikaye commented on PR #12542:
Regarding the note on fuzzing - I guess we don't need to do anything because fuzzing always used the default of enabling backtraces and that isn't changing.
adambratschikaye updated PR #12542.
venkkatesh-sekar submitted PR review.
fitzgen submitted PR review:
Thanks!
fitzgen added PR #12542 Limit the number of frames in backtrace collection to the merge queue.
github-merge-queue[bot] removed PR #12542 Limit the number of frames in backtrace collection from the merge queue.
adambratschikaye requested alexcrichton for a review on PR #12542.
adambratschikaye requested wasmtime-fuzz-reviewers for a review on PR #12542.
adambratschikaye updated PR #12542.
adambratschikaye commented on PR #12542:
@fitzgen Looks like there was a fuzz testing failure and a docs failure when merging. They should be fixed now.
adambratschikaye requested fitzgen for a review on PR #12542.
github-actions[bot] added the label fuzzing on PR #12542.
github-actions[bot] commented on PR #12542:
Subscribe to Label Action
cc @fitzgen
<details>
This issue or pull request has been labeled: "fuzzing", "wasmtime:api", "wasmtime:config"Thus the following users have been cc'd because of the following labels:
- fitzgen: fuzzing
To subscribe or unsubscribe from this label, edit the <code>.github/subscribe-to-label.json</code> configuration file.
Learn more.
</details>
fitzgen submitted PR review:
Thanks! Just one more small thing before we land this. Thanks for your patience!
fitzgen created PR review comment:
Rather than hard-coding a second copy of the default, which means this test will start failing if we ever change the default, can we explicitly set a limit and rely on that in the test here? Even better would be to generate an arbitrary limit as part of the
wasmtime_fuzzing::generators::Stacksstruct, so we fuzz different stack trace limits as well.Should just require adding a
pub limit: Option<NonZeroUsize>,field here:And then adding something like
let limit = NonZeroUsize::new(u.int_in_range(0..=256)?);inside here:And finally creating the config with the limit and an engine from that config inside this current function, rather than using a default config and default engine:
let mut config = Config::new(); config.wasm_backtrace_max_frames(stacks.limit); let engine = Engine::new(&config)?;
adambratschikaye updated PR #12542.
adambratschikaye submitted PR review.
adambratschikaye created PR review comment:
No problem, I made those changes.
adambratschikaye requested fitzgen for a review on PR #12542.
fitzgen submitted PR review:
Thanks!
fitzgen added PR #12542 Limit the number of frames in backtrace collection to the merge queue.
fitzgen merged PR #12542.
fitzgen removed PR #12542 Limit the number of frames in backtrace collection from the merge queue.
adambratschikaye commented on PR #12542:
Thanks @fitzgen
Last updated: Feb 24 2026 at 04:36 UTC