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 exports #357

Merged
merged 3 commits into from
May 29, 2020
Merged

Validate exports #357

merged 3 commits into from
May 29, 2020

Conversation

gumb0
Copy link
Collaborator

@gumb0 gumb0 commented May 28, 2020

No description provided.

@codecov
Copy link

codecov bot commented May 28, 2020

Codecov Report

Merging #357 into master will increase coverage by 0.00%.
The diff coverage is 99.13%.

@@           Coverage Diff            @@
##           master     #357    +/-   ##
========================================
  Coverage   98.84%   98.84%            
========================================
  Files          38       38            
  Lines       11468    11571   +103     
========================================
+ Hits        11335    11437   +102     
- Misses        133      134     +1     

@gumb0 gumb0 marked this pull request as ready for review May 28, 2020 13:36
@gumb0 gumb0 requested review from axic and chfast May 28, 2020 13:39
lib/fizzy/parser.cpp Show resolved Hide resolved
@gumb0 gumb0 force-pushed the validate-exports branch 2 times, most recently from 38a45eb to 05a3574 Compare May 28, 2020 15:33
throw validation_error{"invalid index of an exported function"};
break;
case ExternalKind::Table:
if (export_.index != 0 || !module.has_table())
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Changed to using module class helpers

module.imported_globals_mutability.size() + module.globalsec.size();

// Validate exports.
std::unordered_set<std::string_view> export_names;
Copy link
Member

Choose a reason for hiding this comment

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

Is this much faster than vector or what is the reason?

Copy link
Collaborator

Choose a reason for hiding this comment

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

With set it is straight-forward to check if element exists.

default:
assert(false);
}
if (const auto [_, inserted] = export_names.emplace(export_.name); !inserted)
Copy link
Member

Choose a reason for hiding this comment

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

I so much dislike this syntax of C++17 🤷

Copy link
Member

Choose a reason for hiding this comment

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

if (!std::get<1>(export_names.emplace(export_.name)) isn't nicer.

But this entire thing is in a for loop, so why not just keep these as two statements (like the rest of codebase)?

Copy link
Collaborator

Choose a reason for hiding this comment

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

export_names.emplace(export_.name).second will work.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

changed it to @chfast's suggestion

EXPECT_EQ(module.exportsec[3].name, "xyz");
EXPECT_EQ(module.exportsec[3].kind, ExternalKind::Global);
EXPECT_EQ(module.exportsec[3].index, 0x45);
EXPECT_EQ(module.exportsec[3].index, 0);
Copy link
Member

Choose a reason for hiding this comment

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

Too bad the old test was invalid, but nicer to see what we're testing.

@@ -231,3 +231,68 @@ TEST(validation, call_indirect_no_table)
const auto wasm = from_hex("0061736d0100000001050160017f00030201000a0901070020001101000b");
EXPECT_THROW_MESSAGE(parse(wasm), validation_error, "call_indirect without defined table");
}

TEST(validation, export_invald_index)
Copy link
Member

Choose a reason for hiding this comment

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

invald -> invalid

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

fixed

(export "m" (memory 1))
*/
const auto wasm_mem = from_hex("0061736d010000000503010001070501016d0201");
EXPECT_THROW_MESSAGE(parse(wasm_mem), validation_error, "invalid index of an exported memory");
Copy link
Member

Choose a reason for hiding this comment

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

Should we have different message whether memory/table section is present or not?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think this is fine - 0 is invalid index in some context.

Copy link
Member

@axic axic left a comment

Choose a reason for hiding this comment

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

The change looks good in general, please fix the typo before merging. I'm not too strong on the if statement. Whether to have different message based on table/memory section being present, that is probably a useful question.

@gumb0 gumb0 merged commit 29c7d13 into master May 29, 2020
@gumb0 gumb0 deleted the validate-exports branch May 29, 2020 10:55
@gumb0
Copy link
Collaborator Author

gumb0 commented May 29, 2020

Cases with exporting table/memory 0 when none is defined are missing from the spectests, added to the "to upstream" list.

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