[PATCH] D38777: [wasm] readSection: Avoid reading past eof (fixes oss-fuzz #3219)
Vedant Kumar via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Oct 18 22:35:01 PDT 2017
vsk updated this revision to Diff 119546.
vsk marked an inline comment as done.
vsk edited the summary of this revision.
vsk added a comment.
- Address review feedback, and set aside the dwarfdump changes for later.
https://reviews.llvm.org/D38777
Files:
lib/Object/WasmObjectFile.cpp
test/tools/llvm-objdump/Inputs/corrupt-section.wasm
test/tools/llvm-objdump/wasm-corrupt-section.test
Index: test/tools/llvm-objdump/wasm-corrupt-section.test
===================================================================
--- /dev/null
+++ test/tools/llvm-objdump/wasm-corrupt-section.test
@@ -0,0 +1,2 @@
+# RUN: llvm-objdump -h %p/Inputs/corrupt-section.wasm 2>&1 | FileCheck %s
+# CHECK: '{{.*}}corrupt-section.wasm': Section too large
Index: lib/Object/WasmObjectFile.cpp
===================================================================
--- lib/Object/WasmObjectFile.cpp
+++ lib/Object/WasmObjectFile.cpp
@@ -178,14 +178,16 @@
}
static Error readSection(WasmSection &Section, const uint8_t *&Ptr,
- const uint8_t *Start) {
- // TODO(sbc): Avoid reading past EOF in the case of malformed files.
+ const uint8_t *Start, const uint8_t *Eof) {
Section.Offset = Ptr - Start;
Section.Type = readVaruint7(Ptr);
uint32_t Size = readVaruint32(Ptr);
if (Size == 0)
return make_error<StringError>("Zero length section",
object_error::parse_failed);
+ if (Ptr + Size > Eof)
+ return make_error<StringError>("Section too large",
+ object_error::parse_failed);
Section.Content = ArrayRef<uint8_t>(Ptr, Size);
Ptr += Size;
return Error::success();
@@ -221,7 +223,7 @@
WasmSection Sec;
while (Ptr < Eof) {
- if ((Err = readSection(Sec, Ptr, getPtr(0))))
+ if ((Err = readSection(Sec, Ptr, getPtr(0), Eof)))
return;
if ((Err = parseSection(Sec)))
return;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D38777.119546.patch
Type: text/x-patch
Size: 1534 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20171019/96ac40cc/attachment.bin>
More information about the llvm-commits
mailing list