@@ -296,14 +296,28 @@ wasm::vec<byte_t> V8::getStrippedSource() {
296
296
if (section_len == static_cast <uint32_t >(-1 ) || pos + section_len > end) {
297
297
return wasm::vec<byte_t >::invalid ();
298
298
}
299
- pos += section_len;
300
299
if (section_type == 0 /* custom section */ ) {
301
- if (stripped.empty ()) {
302
- const byte_t *start = source_.get ();
303
- stripped.insert (stripped.end (), start, section_start);
300
+ const auto section_data_start = pos;
301
+ const auto section_name_len = parseVarint (pos, end);
302
+ if (section_name_len == static_cast <uint32_t >(-1 ) || pos + section_name_len > end) {
303
+ return wasm::vec<byte_t >::invalid ();
304
+ }
305
+ auto section_name = std::string_view (pos, section_name_len);
306
+ if (section_name.find (" precompiled_" ) != std::string::npos) {
307
+ // If this is the first "precompiled_" section, then save everything
308
+ // before it, otherwise skip it.
309
+ if (stripped.empty ()) {
310
+ const byte_t *start = source_.get ();
311
+ stripped.insert (stripped.end (), start, section_start);
312
+ }
313
+ }
314
+ pos = section_data_start + section_len;
315
+ } else {
316
+ pos += section_len;
317
+ // Save this section if we already saw a custom "precompiled_" section.
318
+ if (!stripped.empty ()) {
319
+ stripped.insert (stripped.end (), section_start, pos /* section end */ );
304
320
}
305
- } else if (!stripped.empty ()) {
306
- stripped.insert (stripped.end (), section_start, pos /* section end */ );
307
321
}
308
322
}
309
323
0 commit comments