Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(8)

Unified Diff: src/wasm/module-decoder.cc

Issue 1743773002: WebAssembly: skip unknown sections, add names (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | src/wasm/wasm-module.h » ('j') | src/wasm/wasm-module.h » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/wasm/module-decoder.cc
diff --git a/src/wasm/module-decoder.cc b/src/wasm/module-decoder.cc
index 62b000da2bfd8b3d5df0b2c612a027ffe0a64946..d58b31e527911778ea2427fcae8b67b1fcc81bfe 100644
--- a/src/wasm/module-decoder.cc
+++ b/src/wasm/module-decoder.cc
@@ -56,20 +56,29 @@ class ModuleDecoder : public Decoder {
module->function_table = new std::vector<uint16_t>();
module->import_table = new std::vector<WasmImport>();
- bool sections[kMaxModuleSectionCode];
- memset(sections, 0, sizeof(sections));
+ bool sections[kMaxModuleSectionCode] = {false};
// Decode the module sections.
- while (pc_ < limit_) {
+ while (pc_ < limit_ && !failed()) {
TRACE("DecodeSection\n");
- WasmSectionDeclCode section =
- static_cast<WasmSectionDeclCode>(consume_u8("section"));
- // Each section should appear at most once.
- if (section < kMaxModuleSectionCode) {
- CheckForPreviousSection(sections, section, false);
- sections[section] = true;
+ uint8_t section_u8 = consume_u8("section");
+
+ if (section_u8 >= kMaxModuleSectionCode) {
+ // Skip unknown section.
+ int length;
+ for (uint32_t section_bytes = consume_u32v(&length, "globals count");
titzer 2016/02/26 22:54:17 s/globals count/section size/
JF 2016/02/26 23:42:41 Done.
+ section_bytes; --section_bytes) {
+ if (failed()) break;
+ (void)consume_u8("unknown section byte");
titzer 2016/02/26 22:54:17 You can just consume the length and then increment
JF 2016/02/26 23:42:41 Done.
+ }
+ continue;
}
+ // Each section should appear at most once.
+ auto section = static_cast<WasmSectionDeclCode>(section_u8);
+ CheckForPreviousSection(sections, section, false);
+ sections[section] = true;
+
switch (section) {
case kDeclEnd:
// Terminate section decoding.
@@ -234,23 +243,8 @@ class ModuleDecoder : public Decoder {
}
break;
}
- case kDeclWLL: {
- // Reserved for experimentation by the Web Low-level Language project
- // which is augmenting the binary encoding with source code meta
- // information. This section does not affect the semantics of the code
- // and can be ignored by the runtime. https://github.com/JSStats/wll
- int length = 0;
- uint32_t section_size = consume_u32v(&length, "section size");
- if (pc_ + section_size > limit_ || pc_ + section_size < pc_) {
- error(pc_ - length, "invalid section size");
- break;
- }
- pc_ += section_size;
- break;
- }
- default:
- error(pc_ - 1, nullptr, "unrecognized section 0x%02x", section);
- break;
+ case kMaxModuleSectionCode:
+ UNREACHABLE(); // Already skipped unknown sections.
}
}
« no previous file with comments | « no previous file | src/wasm/wasm-module.h » ('j') | src/wasm/wasm-module.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698