aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/ObjectYAML/WasmEmitter.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/lib/ObjectYAML/WasmEmitter.cpp')
-rw-r--r--llvm/lib/ObjectYAML/WasmEmitter.cpp12
1 files changed, 11 insertions, 1 deletions
diff --git a/llvm/lib/ObjectYAML/WasmEmitter.cpp b/llvm/lib/ObjectYAML/WasmEmitter.cpp
index 6230312eff7b..9b8fd11f8543 100644
--- a/llvm/lib/ObjectYAML/WasmEmitter.cpp
+++ b/llvm/lib/ObjectYAML/WasmEmitter.cpp
@@ -646,8 +646,18 @@ bool WasmWriter::writeWasm(raw_ostream &OS) {
StringStream.flush();
+ unsigned HeaderSecSizeEncodingLen =
+ Sec->HeaderSecSizeEncodingLen ? *Sec->HeaderSecSizeEncodingLen : 5;
+ unsigned RequiredLen = getULEB128Size(OutString.size());
+ // Wasm spec does not allow LEBs larger than 5 bytes
+ assert(RequiredLen <= 5);
+ if (HeaderSecSizeEncodingLen < RequiredLen) {
+ reportError("section header length can't be encoded in a LEB of size " +
+ Twine(HeaderSecSizeEncodingLen));
+ return false;
+ }
// Write the section size followed by the content
- encodeULEB128(OutString.size(), OS);
+ encodeULEB128(OutString.size(), OS, HeaderSecSizeEncodingLen);
OS << OutString;
}