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

Validate missing memory #317

Merged
merged 4 commits into from
May 27, 2020
Merged

Validate missing memory #317

merged 4 commits into from
May 27, 2020

Conversation

axic
Copy link
Member

@axic axic commented May 16, 2020

No description provided.

@axic axic force-pushed the validate-missing-memory branch 2 times, most recently from 50692ce to 099ff6a Compare May 16, 2020 21:14
@axic
Copy link
Member Author

axic commented May 21, 2020

Need to add a unit test before merging.

@axic axic force-pushed the validate-missing-memory branch from 099ff6a to c2024e8 Compare May 26, 2020 18:00
@axic axic marked this pull request as ready for review May 26, 2020 18:33
@axic axic force-pushed the validate-missing-memory branch from c2024e8 to f98658d Compare May 26, 2020 18:33
@axic axic requested review from chfast and gumb0 May 26, 2020 18:33
EXPECT_THROW_MESSAGE(parse(bin), parser_error, "unexpected memidx value 1");
}

TEST(parser, DISABLED_empty_data_section_without_memory)
{
const auto bin = bytes{wasm_prefix} + make_section(11, make_vec({}));
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since empty data sections end up being datasec.empty() in the parser, this case is not detected.

@gumb0 did you say the spec states an empty data section can or cannot be present if no memory section is present?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It cannot. Any data section is invalid if no memory is present, according to validation spec.

image

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any suggestion how to clearly support that in our code? Since section kind's are strictly ordered (and we enforce that already), the best option seems to be moving the check into the switch statement right before parse_vec<Data>. What do you think?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It requires info about imports, so to move data and element section checks into the switch, you would need to move "split imports" loop inside case SectionId::import, too.

I'm fine in this PR to leave like it is now.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The current check covers empty data section, too, doesn't it? So this test can be just enabled?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The current check covers empty data section, too, doesn't it? So this test can be just enabled?

It does not, if it is enabled it fails. You can try yourself and perhaps come up with a clever solution.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I misunderstood what is '"empty data section", I thought it's "data section with empty data vector" (that would be invalid), but you mean "section consisting of empty vector". I can't find any restriction for a data section as a whole, I guess any section with empty contents is allowed.

Also, in binary spec it says:
image

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good find, will take your change then.

@axic axic force-pushed the validate-missing-memory branch from f98658d to 92789f8 Compare May 27, 2020 15:15
@axic axic requested a review from gumb0 May 27, 2020 15:15
@axic axic force-pushed the validate-missing-memory branch from 92789f8 to 0ea3f2a Compare May 27, 2020 16:17
@codecov
Copy link

codecov bot commented May 27, 2020

Codecov Report

Merging #317 into master will increase coverage by 0.00%.
The diff coverage is 100.00%.

@@           Coverage Diff           @@
##           master     #317   +/-   ##
=======================================
  Coverage   99.11%   99.11%           
=======================================
  Files          38       38           
  Lines       11162    11176   +14     
=======================================
+ Hits        11063    11077   +14     
  Misses         99       99           

@axic axic merged commit fe5ac19 into master May 27, 2020
@axic axic deleted the validate-missing-memory branch May 27, 2020 16:45
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