Skip to content

[spec] Parsing and validation in a single pass seems to be discouraged #1170

Closed

Description

@axic

This test case in binary.wast (https://github.com/WebAssembly/spec/blob/v1.1/test/core/binary.wast#L739-L759) tests for assert_malformed, e.g. parser error. However it also contains a validation error.

This turns out to pose a difficulty to engines, which would try to do parsing and (or a part of) validation in a single pass.

Is this intentional?

Activity

  1. rossberg commented on Mar 31, 2020

    @rossberg
    Member

    No, every negative test should contain only one mistake. But it's easy to miss cases where that's not the case. Happy to accept fixes. :)

  2. chfast commented on Apr 16, 2020

    @chfast
    Contributor

    Problem

    The problematic test checks br_table "with inconsistent target count (2 declared, 1 given)". But the intention is quite distant from how binary parser works. I.e. it assumes the parser fails because there is not enough targets provided

    0e02 00 (missing LEB128 encoded target)
    

    but the parser will just consume the next byte being the end 0b.

    0e02 00 0b
    

    and will fail because of the missing final 0b later. Even the test error message suggests that.

    The problem is that in the middle we have br_table with 2 targets: 00 and 0b, where 0b one is invalid. The module is considered invalid before we are able to realize it is malformed.

    Solution

    1. We can just drop the test.
    2. Or to preserve more/less the current cause of being malformed we can add some workaround/hacks preventing the additionally consumed byte seen as invalid br_table target. The only idea I have to achieve that is to make 0b target valid by adding 10 more functions to the module.
  3. binji commented on Apr 16, 2020

    @binji
    Member

    The only idea I have to achieve that is to make 0b target valid by adding 10 more functions to the module.

    Right, though you would need to add blocks, not functions. I think it should work, as long as you made the br_table target length long enough too, so it attempts to access outside of the code section.

  4. added a commit that references this issue on Jan 11, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions