forked from bytecodealliance/wasm-tools
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix an accidental regression from bytecodealliance#697
This commit fixes a regression introduced in bytecodealliance#697 which could cause a panic when validating an invalid wasm module. The issue introduced was that a [check that the control stack is non-empty][check] was lost in the refactoring of the operator validator. This check ran for every single operator and verified that there was a frame on the control stack that the operator could be attached to, otherwise it means instructions were present after the end of the function. The current design of `VisitOperator` doesn't have an easy place to slot this in so I decided to fix this via a different route than was implemented before. Anything which operates on the control stack now checks to see if it's empty instead of asserting it's non-empty. Operators which don't touch the control stack are then checked by ensuring that the `end` opcode which emptied the control stack was the last operator processed in the function. This exposed a minor issue where when validating const expressions the offset that was passed in as the final offset of the expression was actually the first offset of the expression. Additionally this adds some tests to exercise this corner case (unsure why the spec test suite doesn't have them already!) [check]: https://github.com/bytecodealliance/wasm-tools/blob/8732e0bc8a579cd9f15d9134af997c5d3d95af5d/crates/wasmparser/src/validator/operators.rs#L581-L583
- Loading branch information
1 parent
63f8ab3
commit 2af0eaf
Showing
4 changed files
with
99 additions
and
15 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
(assert_invalid | ||
(module binary | ||
"\00asm" "\01\00\00\00" ;; magic header | ||
|
||
"\01\04" ;; type section | ||
"\01" ;; 1 count | ||
"\60\00\00" ;; no params or results | ||
|
||
"\03\02" ;; func section | ||
"\01" ;; 1 count | ||
"\00" ;; type 0 | ||
|
||
"\0a\05" ;; code section | ||
"\01" ;; 1 count | ||
"\03" ;; size of function | ||
"\00" ;; no locals | ||
"\0b" ;; end | ||
"\01" ;; nop | ||
) | ||
"operators remaining after end of function") | ||
|
||
(assert_invalid | ||
(module binary | ||
"\00asm" "\01\00\00\00" ;; magic header | ||
|
||
"\01\04" ;; type section | ||
"\01" ;; 1 count | ||
"\60\00\00" ;; no params or results | ||
|
||
"\03\02" ;; func section | ||
"\01" ;; 1 count | ||
"\00" ;; type 0 | ||
|
||
"\0a\05" ;; code section | ||
"\01" ;; 1 count | ||
"\03" ;; size of function | ||
"\00" ;; no locals | ||
"\0b" ;; end | ||
"\9d" ;; f64.trunc | ||
) | ||
"operators remaining after end of function") | ||
|
||
(assert_invalid | ||
(module binary | ||
"\00asm" "\01\00\00\00" ;; magic header | ||
|
||
"\01\04" ;; type section | ||
"\01" ;; 1 count | ||
"\60\00\00" ;; no params or results | ||
|
||
"\03\02" ;; func section | ||
"\01" ;; 1 count | ||
"\00" ;; type 0 | ||
|
||
"\0a\05" ;; code section | ||
"\01" ;; 1 count | ||
"\03" ;; size of function | ||
"\00" ;; no locals | ||
"\0b" ;; end | ||
"\0b" ;; end | ||
) | ||
"operators remaining after end of function") |