[PATCH] D50387: [WASM] Fix overflow when reading custom section

Jonas Devlieghere via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Aug 8 04:56:30 PDT 2018


JDevlieghere updated this revision to Diff 159685.
JDevlieghere added a comment.

Updated to use the ReadContext. If the error message doesn't matter that much then I agree this is better.


https://reviews.llvm.org/D50387

Files:
  llvm/lib/Object/WasmObjectFile.cpp
  llvm/test/Object/Inputs/WASM/string-outside-section.wasm
  llvm/test/Object/wasm-string-outside-section.test


Index: llvm/test/Object/wasm-string-outside-section.test
===================================================================
--- /dev/null
+++ llvm/test/Object/wasm-string-outside-section.test
@@ -0,0 +1,3 @@
+RUN: not llvm-objdump -s %p/Inputs/WASM/string-outside-section.wasm 2>&1 | FileCheck %s
+
+CHECK: LLVM ERROR: EOF while reading string
Index: llvm/lib/Object/WasmObjectFile.cpp
===================================================================
--- llvm/lib/Object/WasmObjectFile.cpp
+++ llvm/lib/Object/WasmObjectFile.cpp
@@ -216,9 +216,16 @@
     return make_error<StringError>("Section too large",
                                    object_error::parse_failed);
   if (Section.Type == wasm::WASM_SEC_CUSTOM) {
-    const uint8_t *NameStart = Ctx.Ptr;
-    Section.Name = readString(Ctx);
-    Size -= Ctx.Ptr - NameStart;
+    WasmObjectFile::ReadContext SectionCtx;
+    SectionCtx.Start = Ctx.Ptr;
+    SectionCtx.Ptr = Ctx.Ptr;
+    SectionCtx.End = Ctx.Ptr + Size;
+
+    Section.Name = readString(SectionCtx);
+
+    uint32_t SectionNameSize = SectionCtx.Ptr - SectionCtx.Start;
+    Ctx.Ptr += SectionNameSize;
+    Size -= SectionNameSize;
   }
   Section.Content = ArrayRef<uint8_t>(Ctx.Ptr, Size);
   Ctx.Ptr += Size;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D50387.159685.patch
Type: text/x-patch
Size: 1241 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180808/553b5346/attachment.bin>


More information about the llvm-commits mailing list