mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-11-25 12:12:47 +01:00
[WASM] Fix overflow when reading custom section
When reading a custom WASM section, it was possible that its name extended beyond the size of the section. This resulted in a bogus value for the section size due to the size overflowing. Fixes heap buffer overflow detected by OSS-fuzz: https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=8190 Differential revision: https://reviews.llvm.org/D50387 llvm-svn: 339269
This commit is contained in:
parent
d73939381b
commit
b42f11290d
@ -216,9 +216,16 @@ static Error readSection(WasmSection &Section,
|
||||
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;
|
||||
|
BIN
test/Object/Inputs/WASM/string-outside-section.wasm
Normal file
BIN
test/Object/Inputs/WASM/string-outside-section.wasm
Normal file
Binary file not shown.
3
test/Object/wasm-string-outside-section.test
Normal file
3
test/Object/wasm-string-outside-section.test
Normal file
@ -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
|
Loading…
Reference in New Issue
Block a user