Skip to content
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

Update blockty printing and space handling #799

Merged
merged 2 commits into from Oct 14, 2022

Conversation

alexcrichton
Copy link
Member

This commit fixes a minor issue found during fuzzing that is a regression from #795. Specifically some encodings of block types would lead to printing the binary format with two spaces after the block instruction but printing again would only print one space. This was due to a number of issues fixed in this commit:

  • Primarily wasmprinter has been reorganized to no longer assume some methods print the leading whitespace. This basically "randomly" moves around space printing in wasmprinter. To help make this less "random" I've also added a test in roundtrip.rs that all whitespace tokens in the wasmprinter-produced output are not "bad whitespace" which means there's no trailing whitespace or double-spaces printed. This caught a few issues with prior iterations of this commit

  • Additionally when looking more at block type parsing and printing I was reminded that much of the processing here was an artifact of historical compatibility with wabt where wabt canonicalized non-MVP encodings into MVP encodings where possible. I removed this canonicalization to remain faithful to the original binary format since wabt is no longer used as a reference test. This was orthogonal to the spacing changes above but was something that seemed like it should be fixed regardless. A *.dump test was added to assert that the encodings are as expected and not canonicalized, even when possible.

This commit fixes a minor issue found during fuzzing that is a
regression from bytecodealliance#795. Specifically some encodings of block types would
lead to printing the binary format with two spaces after the `block`
instruction but printing again would only print one space. This was due
to a number of issues fixed in this commit:

* Primarily `wasmprinter` has been reorganized to no longer assume some
  methods print the leading whitespace. This basically "randomly" moves
  around space printing in `wasmprinter`. To help make this less
  "random" I've also added a test in `roundtrip.rs` that all whitespace
  tokens in the `wasmprinter`-produced output are not "bad whitespace"
  which means there's no trailing whitespace or double-spaces printed.
  This caught a few issues with prior iterations of this commit

* Additionally when looking more at block type parsing and printing I
  was reminded that much of the processing here was an artifact of
  historical compatibility with `wabt` where `wabt` canonicalized
  non-MVP encodings into MVP encodings where possible. I removed this
  canonicalization to remain faithful to the original binary format
  since `wabt` is no longer used as a reference test. This was
  orthogonal to the spacing changes above but was something that seemed
  like it should be fixed regardless. A `*.dump` test was added to
  assert that the encodings are as expected and not canonicalized, even
  when possible.
@alexcrichton alexcrichton merged commit 1fecc98 into bytecodealliance:main Oct 14, 2022
@alexcrichton alexcrichton deleted the fix-fuzzing branch October 14, 2022 17:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants