diff options
Diffstat (limited to 'src/wasm-binary.h')
-rw-r--r-- | src/wasm-binary.h | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/src/wasm-binary.h b/src/wasm-binary.h index 2f2df7c9b..921f90ac8 100644 --- a/src/wasm-binary.h +++ b/src/wasm-binary.h @@ -94,13 +94,16 @@ struct LEB { : ((mask_type(1) << (sizeof(T) * 8 - shift)) - 1u); T significant_payload = payload & shift_mask; if (significant_payload != payload) { - assert(std::is_signed<T>::value && last && - "dropped bits only valid for signed LEB"); + if (!(std::is_signed<T>::value && last)) { + throw ParseException("LEB dropped bits only valid for signed LEB"); + } } value |= significant_payload << shift; if (last) break; shift += 7; - assert(size_t(shift) < sizeof(T) * 8 && "LEB overflow"); + if (size_t(shift) >= sizeof(T) * 8) { + throw ParseException("LEB overflow"); + } } // If signed LEB, then we might need to sign-extend. (compile should // optimize this out if not needed). @@ -110,7 +113,9 @@ struct LEB { size_t sext_bits = 8 * sizeof(T) - size_t(shift); value <<= sext_bits; value >>= sext_bits; - assert(value < 0 && "sign-extend should produces a negative value"); + if (value >= 0) { + throw ParseException(" LEBsign-extend should produce a negative value"); + } } } } @@ -640,6 +645,8 @@ class WasmBinaryBuilder { size_t pos = 0; Index startIndex = -1; + std::set<BinaryConsts::Section> seenSections; + public: WasmBinaryBuilder(Module& wasm, std::vector<char>& input, bool debug) : wasm(wasm), allocator(wasm.allocator), input(input), debug(debug) {} |