Skip to content

Commit

Permalink
review: strip only Custom Sections with precompiled modules.
Browse files Browse the repository at this point in the history
Signed-off-by: Piotr Sikora <[email protected]>
  • Loading branch information
PiotrSikora committed Oct 15, 2020
1 parent 1c18f7e commit bbf108b
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions test/tools/wee8_compile/wee8_compile.cc
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,22 @@ wasm::vec<byte_t> stripWasmModule(const wasm::vec<byte_t>& module) {
std::cerr << "ERROR: Failed to parse corrupted Wasm module." << std::endl;
return wasm::vec<byte_t>::invalid();
}
if (section_type != 0 /* custom section */) {
if (section_type == 0 /* custom section */) {
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) {
std::cerr << "ERROR: Failed to parse corrupted Wasm module." << std::endl;
return wasm::vec<byte_t>::invalid();
}
if (section_name_len < sizeof("precompiled_") - 1 ||
::memcmp(pos, "precompiled_", sizeof("precompiled_") - 1) != 0) {
stripped.insert(stripped.end(), section_start, section_data_start + section_len);
}
pos = section_data_start + section_len;
} else {
stripped.insert(stripped.end(), section_start, pos + section_len);
pos += section_len;
}
pos += section_len;
}

return wasm::vec<byte_t>::make(stripped.size(), stripped.data());
Expand Down

0 comments on commit bbf108b

Please sign in to comment.