[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 09:34:42 PDT 2018


This revision was automatically updated to reflect the committed changes.
Closed by commit rL339269: [WASM] Fix overflow when reading custom section (authored by JDevlieghere, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D50387?vs=159685&id=159740#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D50387

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


Index: llvm/trunk/lib/Object/WasmObjectFile.cpp
===================================================================
--- llvm/trunk/lib/Object/WasmObjectFile.cpp
+++ llvm/trunk/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;
Index: llvm/trunk/test/Object/wasm-string-outside-section.test
===================================================================
--- llvm/trunk/test/Object/wasm-string-outside-section.test
+++ llvm/trunk/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


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


More information about the llvm-commits mailing list