Skip to content

Conversation

@cjamthagen
Copy link
Contributor

Some validation added for the Type, Import and Export sections. By no means complete, and sorry for the lack of tests so far.

Running out of time and wanted to get something up, so please feel free to leave this PR unmerged, and I could pick it up later.

@cjamthagen
Copy link
Contributor Author

cjamthagen commented Aug 30, 2017

Below is a task list of all the validation required for the various sections found at https://github.com/sunfishcode/wasm-reference-manual/blob/master/WebAssembly.md. I hope this gives a better overview of what needs to be done and that it eases reviewing efforts.

  • Type Section
    • form is required to be func.
    • Each returns array is required to contain at most one element.
  • Import Section
    • All global imports are required to be immutable.
    • Each import is required to be resolved by the embedding environment.
    • A linear-memory import's minimum length is required to be at most the imported linear memory's minimum length.
    • A linear-memory import is required to have a maximum length if the imported linear memory has a maximum length.
    • If present, a linear-memory import's maximum length is required to be at least the imported linear memory's maximum length.
    • A table import's minimum length is required to be at most the imported table's minimum length.
    • A table import is required to have a maximum length if the imported table has a maximum length.
    • If present, a table import's maximum length is required to be at least the imported table's maximum length.
    • Embedding-environment-specific validation requirements may be required of each import.
  • Function Section
    • The array is required to be the same length as the Code Section array.
  • Global Section
    • The type of the value returned by init must be the same as desc's type.
  • Export Section
    • Each export's `name' is required to be unique among all the exports' names.
    • Each export's index is required to be within the bounds of its associated index space.
  • Start Section
    • The index is required to be within the bounds of the Code Section array.
    • The function signature indexed in the Type Section is required to have an empty parameter list and an empty return list.

If I have missed any validation requirements please let me know and I'll add them. I will continue working on this for the next couple of days and update the task list accordingly.

@coveralls
Copy link

coveralls commented Aug 30, 2017

Coverage Status

Coverage decreased (-0.9%) to 21.63% when pulling 4cc160f on cjamthagen:validation into 13dd114 on TrueBitFoundation:master.

1 similar comment
@coveralls
Copy link

coveralls commented Aug 30, 2017

Coverage Status

Coverage decreased (-0.9%) to 21.63% when pulling 4cc160f on cjamthagen:validation into 13dd114 on TrueBitFoundation:master.

@cjamthagen
Copy link
Contributor Author

Refactored test.py and added unit tests to make sure section validation fails as its supposed to.

Hmm.. maybe I should break this PR down to one per section? @Bloodstalker

@terminaldweller
Copy link
Collaborator

terminaldweller commented Aug 31, 2017

that would make reading it easier for me but you don't have to.

@coveralls
Copy link

coveralls commented Aug 31, 2017

Coverage Status

Coverage decreased (-12.1%) to 70.141% when pulling c641e55 on cjamthagen:validation into a498c77 on TrueBitFoundation:master.

@cjamthagen
Copy link
Contributor Author

Alright, I will limit this PR to sections I have started working on and do the rest separately.

@terminaldweller
Copy link
Collaborator

ok. thank you.

@coveralls
Copy link

coveralls commented Sep 1, 2017

Coverage Status

Coverage decreased (-12.1%) to 70.141% when pulling 08106e8 on cjamthagen:validation into a498c77 on TrueBitFoundation:master.

Retrieve latest appended module for validation and break search loop
when section is found.
* form is required to be func.
* Each returns array is required to contain at most one element.
* All global imports are required to be immutable.

Add classes with constants to improve code readability.
* Each export's name is required to be unique among all the exports'
names.
* Each export's index is required to be within the bounds of its
associated index space.

Also populate module index spaces in Module constructor.
* The array is required to be the same length as the Code Section array.
* The type of the value returned by init must be the same as desc's type.
* The index is required to be within the bounds of the Code Section array.
This commit adds tests and invalid wasm testfiles that checks the type section.

The file invalid_form.wasm is based on testsuite/address.wasm and was
edited to have the first entry of the type section include an invalid
form (0x60 => 0x61).

The file invalid_retcount.wasm is also based on testsuite/address.wasm
and was edited to have the first type section entry include two return
values instead of one.
The file incompatible_init_desc_type.wasm is based on the file
testsuite/globals.wasm and has the first global declaration in the
global section edited to change the global description type from 0x7f
to 0x7e, thus making it incompatible with the type returned from the
instantiation-time initializer.
Also make sure invalid_retcount.wasm test is properly formatted so
parser doesn't crash.
@coveralls
Copy link

coveralls commented Sep 1, 2017

Coverage Status

Coverage decreased (-12.2%) to 70.038% when pulling f072bc9 on cjamthagen:validation into 5a7395a on TrueBitFoundation:master.

1 similar comment
@coveralls
Copy link

Coverage Status

Coverage decreased (-12.2%) to 70.038% when pulling f072bc9 on cjamthagen:validation into 5a7395a on TrueBitFoundation:master.

@coveralls
Copy link

coveralls commented Sep 1, 2017

Coverage Status

Coverage decreased (-12.1%) to 70.141% when pulling 85b409f on cjamthagen:validation into 5a7395a on TrueBitFoundation:master.

1 similar comment
@coveralls
Copy link

coveralls commented Sep 1, 2017

Coverage Status

Coverage decreased (-12.1%) to 70.141% when pulling 85b409f on cjamthagen:validation into 5a7395a on TrueBitFoundation:master.

@coveralls
Copy link

coveralls commented Sep 6, 2017

Coverage Status

Coverage decreased (-14.3%) to 67.951% when pulling 347f65d on cjamthagen:validation into 5a7395a on TrueBitFoundation:master.

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.

3 participants