From 559c3372cfc68a338a204f58cb5e559a35f4ae4b Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Tue, 5 Apr 2016 11:24:50 -0700 Subject: reorder section size location in binary format, see design#639 --- src/wasm-binary.h | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/wasm-binary.h b/src/wasm-binary.h index 5695cffcc..70ee7fe29 100644 --- a/src/wasm-binary.h +++ b/src/wasm-binary.h @@ -486,9 +486,8 @@ public: int32_t startSection(const char* name) { // emit 5 bytes of 0, which we'll fill with LEB later - auto ret = writeU32LEBPlaceholder(); writeInlineString(name); - return ret; + return writeU32LEBPlaceholder(); } void finishSection(int32_t start) { @@ -1135,9 +1134,8 @@ public: // read sections until the end while (more()) { - auto sectionSize = getU32LEB(); - assert(sectionSize < pos + input.size()); auto nameSize = getU32LEB(); + uint32_t sectionSize, before; auto match = [&](const char* name) { for (size_t i = 0; i < nameSize; i++) { if (pos + i >= input.size()) return false; @@ -1145,7 +1143,11 @@ public: if (input[pos + i] != name[i]) return false; } if (strlen(name) != nameSize) return false; + // name matched, read section size and then section itself pos += nameSize; + sectionSize = getU32LEB(); + before = pos; + assert(pos + sectionSize < input.size()); return true; }; if (match(BinaryConsts::Section::Start)) readStart(); @@ -1164,6 +1166,7 @@ public: } else { abort(); } + assert(pos == before + sectionSize); } processFunctions(); -- cgit v1.2.3