Skip to content
This repository was archived by the owner on Mar 28, 2020. It is now read-only.

Commit 2b1f6c2

Browse files
committed
[Bitcode] Fix an unsigned integer overflow while parsing bitcode wrapper header
Specially crafted bitcode wrapper headers can cause unsigned interger overflow and lead to crashes when wrapping around. Fix the offset check and avoid such scenarios. Writing a testcase for this would involve editing the binary to generate values that trigger the overflow, since this would never happen while generating the bitcode in regular compilation flows, so there's currently no feasible way add one. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@268881 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent ba458cf commit 2b1f6c2

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

include/llvm/Bitcode/ReaderWriter.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,9 +162,10 @@ namespace llvm {
162162

163163
unsigned Offset = support::endian::read32le(&BufPtr[BWH_OffsetField]);
164164
unsigned Size = support::endian::read32le(&BufPtr[BWH_SizeField]);
165+
uint64_t BitcodeOffsetEnd = (uint64_t)Offset + (uint64_t)Size;
165166

166167
// Verify that Offset+Size fits in the file.
167-
if (VerifyBufferSize && Offset+Size > unsigned(BufEnd-BufPtr))
168+
if (VerifyBufferSize && BitcodeOffsetEnd > uint64_t(BufEnd-BufPtr))
168169
return true;
169170
BufPtr += Offset;
170171
BufEnd = BufPtr+Size;

0 commit comments

Comments
 (0)