fix(parser): handle single-line functions in parseWast#5
Open
Owanesh wants to merge 1 commit intoSKKU-SecLab:mainfrom
Open
fix(parser): handle single-line functions in parseWast#5Owanesh wants to merge 1 commit intoSKKU-SecLab:mainfrom
Owanesh wants to merge 1 commit intoSKKU-SecLab:mainfrom
Conversation
Empty-body functions like (func $f (type $t0) (param $p0 i32))` have balanced brackets on a single line, so `func_bracketNum` drops to 0 immediately. The parser never finalized them, leaking their header into the next function's header list. `opaque_predicate_insertion` then appended `(local $wadelocal i32)` to the wrong line, producing invalid .wat that breaks wat2wasm
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.
Closes #4
wasmParser/parser.py-- finalize single-line functions immediatelyAfter matching
(func ...), check iffunc_bracketNum == 0. If so, the function has no body and should be finalized on the spot:This prevents the header from leaking into the next function's header list.
strategies/code_perturbation.py-- skip empty-body functions inopaque_predicate_insertionExtend the guard to also skip functions with an empty body (no instructions means no blocks to insert predicates into):
After fix
swamped obfuscate repro.wasm -o out.wasm -s opaque_predicate_insertion --seed 42 --ratio 0.5 # [+] Done! Output: out.wasmThe generated WAT now correctly preserves empty-body functions untouched and only inserts predicates into functions that have actual control-flow blocks: