Skip to content

Commit

Permalink
Fix an overflow issue at BackpatchWord
Browse files Browse the repository at this point in the history
This happens when generating a huge file by LTO, for example, with -gmlt.
When BitNo is > 2^35, ByteNo is overflowed, and an incorrect output offset is overwritten.
This generates ill-formed bitcodes.

Reviewed-by: tejohnson, vitalybuka

Differential Revision: https://reviews.llvm.org/D86645
  • Loading branch information
stephan-yichao-zhao committed Aug 27, 2020
1 parent d7461b3 commit df182eb
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion llvm/include/llvm/Bitstream/BitstreamWriter.h
Expand Up @@ -103,7 +103,7 @@ class BitstreamWriter {
/// with the specified value.
void BackpatchWord(uint64_t BitNo, unsigned NewWord) {
using namespace llvm::support;
unsigned ByteNo = BitNo / 8;
uint64_t ByteNo = BitNo / 8;
assert((!endian::readAtBitAlignment<uint32_t, little, unaligned>(
&Out[ByteNo], BitNo & 7)) &&
"Expected to be patching over 0-value placeholders");
Expand Down

0 comments on commit df182eb

Please sign in to comment.