Skip to content

Commit 67348c8

Browse files
committed
[Bitstream] Check for unterminated VBR
This avoid shift larger than bitwidth UB.
1 parent 13ac039 commit 67348c8

File tree

5 files changed

+13
-19
lines changed

5 files changed

+13
-19
lines changed

llvm/include/llvm/Bitstream/BitstreamReader.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,10 @@ class SimpleBitstreamCursor {
247247
return Result;
248248

249249
NextBit += NumBits-1;
250+
if (NextBit >= 32)
251+
return createStringError(std::errc::illegal_byte_sequence,
252+
"Unterminated VBR");
253+
250254
MaybeRead = Read(NumBits);
251255
if (!MaybeRead)
252256
return MaybeRead;
@@ -274,6 +278,10 @@ class SimpleBitstreamCursor {
274278
return Result;
275279

276280
NextBit += NumBits-1;
281+
if (NextBit >= 64)
282+
return createStringError(std::errc::illegal_byte_sequence,
283+
"Unterminated VBR");
284+
277285
MaybeRead = Read(NumBits);
278286
if (!MaybeRead)
279287
return MaybeRead;
Binary file not shown.

llvm/test/Bitcode/invalid-no-ubsan.test

Lines changed: 0 additions & 19 deletions
This file was deleted.

llvm/test/Bitcode/invalid.test

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,3 +266,8 @@ RUN: not llvm-dis -disable-output %p/Inputs/invalid-value-symbol-table.bc 2>&1 |
266266
RUN: FileCheck --check-prefix=INVALID-VALUE-SYMBOL-TABLE %s
267267

268268
INVALID-VALUE-SYMBOL-TABLE: Invalid value reference in symbol table
269+
270+
RUN: not llvm-dis -disable-output %p/Inputs/unterminated-vbr.bc 2>&1 | \
271+
RUN: FileCheck --check-prefix=UNTERMINATED-VBR %s
272+
273+
UNTERMINATED-VBR: Unterminated VBR

0 commit comments

Comments
 (0)