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. |
} |
} |