Skip to content

Commit 295640c

Browse files
authored
Merge branch 'master' into trace-print
2 parents 8bdd67d + 40fd3d0 commit 295640c

File tree

1 file changed

+20
-6
lines changed

1 file changed

+20
-6
lines changed

src/v8/v8.cc

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -324,14 +324,28 @@ wasm::vec<byte_t> V8::getStrippedSource() {
324324
if (section_len == static_cast<uint32_t>(-1) || pos + section_len > end) {
325325
return wasm::vec<byte_t>::invalid();
326326
}
327-
pos += section_len;
328327
if (section_type == 0 /* custom section */) {
329-
if (stripped.empty()) {
330-
const byte_t *start = source_.get();
331-
stripped.insert(stripped.end(), start, section_start);
328+
const auto section_data_start = pos;
329+
const auto section_name_len = parseVarint(pos, end);
330+
if (section_name_len == static_cast<uint32_t>(-1) || pos + section_name_len > end) {
331+
return wasm::vec<byte_t>::invalid();
332+
}
333+
auto section_name = std::string_view(pos, section_name_len);
334+
if (section_name.find("precompiled_") != std::string::npos) {
335+
// If this is the first "precompiled_" section, then save everything
336+
// before it, otherwise skip it.
337+
if (stripped.empty()) {
338+
const byte_t *start = source_.get();
339+
stripped.insert(stripped.end(), start, section_start);
340+
}
341+
}
342+
pos = section_data_start + section_len;
343+
} else {
344+
pos += section_len;
345+
// Save this section if we already saw a custom "precompiled_" section.
346+
if (!stripped.empty()) {
347+
stripped.insert(stripped.end(), section_start, pos /* section end */);
332348
}
333-
} else if (!stripped.empty()) {
334-
stripped.insert(stripped.end(), section_start, pos /* section end */);
335349
}
336350
}
337351

0 commit comments

Comments
 (0)