Skip to content

Commit bf17cb2

Browse files
committed
[Bitstream] Make MaxChunkSize word-size independent
We only support chunks <= 32 bits regardless of whether we're running on a 64-bit platform or not. Chunk size > 32 <= 64 would cause UB in the reading code.
1 parent 6d52ea8 commit bf17cb2

File tree

3 files changed

+7
-4
lines changed

3 files changed

+7
-4
lines changed

llvm/include/llvm/Bitstream/BitstreamReader.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,6 @@ class SimpleBitstreamCursor {
9797
unsigned BitsInCurWord = 0;
9898

9999
public:
100-
static const constexpr size_t MaxChunkSize = sizeof(word_t) * 8;
101-
102100
SimpleBitstreamCursor() = default;
103101
explicit SimpleBitstreamCursor(ArrayRef<uint8_t> BitcodeBytes)
104102
: BitcodeBytes(BitcodeBytes) {}
@@ -187,7 +185,7 @@ class SimpleBitstreamCursor {
187185
}
188186

189187
Expected<word_t> Read(unsigned NumBits) {
190-
static const unsigned BitsInWord = MaxChunkSize;
188+
static const unsigned BitsInWord = sizeof(word_t) * 8;
191189

192190
assert(NumBits && NumBits <= BitsInWord &&
193191
"Cannot return zero or more than BitsInWord bits!");
@@ -372,7 +370,7 @@ class BitstreamCursor : SimpleBitstreamCursor {
372370
BitstreamBlockInfo *BlockInfo = nullptr;
373371

374372
public:
375-
static const size_t MaxChunkSize = sizeof(word_t) * 8;
373+
static const size_t MaxChunkSize = 32;
376374

377375
BitstreamCursor() = default;
378376
explicit BitstreamCursor(ArrayRef<uint8_t> BitcodeBytes)
24 Bytes
Binary file not shown.

llvm/test/Bitcode/invalid.test

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,3 +276,8 @@ RUN: not llvm-dis -disable-output %p/Inputs/comdat-name-too-large.bc 2>&1 | \
276276
RUN: FileCheck --check-prefix=COMDAT-NAME-TOO-LARGE %s
277277

278278
COMDAT-NAME-TOO-LARGE: Comdat name size too large
279+
280+
RUN: not llvm-dis -disable-output %p/Inputs/invalid-chunk-size.bc 2>&1 | \
281+
RUN: FileCheck --check-prefix=INVALID-CHUNK-SIZE %s
282+
283+
INVALID-CHUNK-SIZE: Fixed or VBR abbrev record with size > MaxChunkData

0 commit comments

Comments
 (0)