Skip to content

Strip only Custom Sections with precompiled Wasm modules. #81

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

Merged
merged 3 commits into from
Oct 27, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 20 additions & 6 deletions src/v8/v8.cc
Original file line number Diff line number Diff line change
Expand Up @@ -296,14 +296,28 @@ wasm::vec<byte_t> V8::getStrippedSource() {
if (section_len == static_cast<uint32_t>(-1) || pos + section_len > end) {
return wasm::vec<byte_t>::invalid();
}
pos += section_len;
if (section_type == 0 /* custom section */) {
if (stripped.empty()) {
const byte_t *start = source_.get();
stripped.insert(stripped.end(), start, section_start);
const auto section_data_start = pos;
const auto section_name_len = parseVarint(pos, end);
if (section_name_len == static_cast<uint32_t>(-1) || pos + section_name_len > end) {
return wasm::vec<byte_t>::invalid();
}
auto section_name = std::string_view(pos, section_name_len);
if (section_name.find("precompiled_") != std::string::npos) {
// If this is the first "precompiled_" section, then save everything
// before it, otherwise skip it.
if (stripped.empty()) {
const byte_t *start = source_.get();
stripped.insert(stripped.end(), start, section_start);
}
}
pos = section_data_start + section_len;
} else {
pos += section_len;
// Save this section if we already saw a custom "precompiled_" section.
if (!stripped.empty()) {
stripped.insert(stripped.end(), section_start, pos /* section end */);
}
} else if (!stripped.empty()) {
stripped.insert(stripped.end(), section_start, pos /* section end */);
}
}

Expand Down