Add opt-in parser limits for untrusted modules - #67
Merged
explodingcamera merged 1 commit intoSep 26, 2026
Merged
explodingcamera merged 1 commit into
explodingcamera merged 1 commit into
Conversation
Owner
|
thanks for the pr! Sounds very reasonable, I'll just push a small follow up commit simplifying some of it. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Related to #66. TinyWasm's default validator limits are deliberately broad for general WASM. For host that loads untrusted guest programs, a small binary can still encode disproportionate parse work (like a large local declaration or
array.new_fixedcount).This adds opt-in
ParseLimitstoParserOptionsfor encoded module bytes, entries per section, parameters plus locals per function,br_tabletargets, andarray.new_fixedelements. Byte, file, and stream entrypoints share the input limit; streaming counts total bytes read even when its buffer slides. The two operator fanouts are checked before wasmparser validation and lowering. Compact-import expansion is counted before validation when the section limit is set.All limits default to unlimited. The ordinary parser path and interpreter dispatch are unchanged; hosts that enable operator fanout limits take a guarded parser-only decode path. Validation should remain enabled for untrusted modules. These are input and known-amplification limits, not a hard peak-memory or elapsed-time guarantee: wasmparser can allocate while decoding a recursive type group before TinyWasm checks its expanded size.
With limits in place, some pathological .wasm files now get properly rejected on my Apple Watch test app, instead of the app crashing.
Local Mac validation: 50,000 deterministic fuzz mutations of adversarial parser fixtures. I also looked at guard techniques from other WASM parsers/runtimes test suites and rolled some of those tests in.