This is an archive of the discontinued LLVM Phabricator instance.

Fix a 32-bit overflow issue when reading LTO-generated bitcode files whose strtab are of size > 2^29
ClosedPublic

Authored by stephan.yichao.zhao on Aug 24 2020, 5:47 PM.

Details

Summary

This happens when using -flto and -Wl,--plugin-opt=emit-llvm to create a linked LTO bitcode file, and the bitcode file has a strtab with size > 2^29.

The code path is GetBitcodeFileContents->readBlobInRecord->readRecord

All the changes relate to a pattern like this

size_t x64 = y64 + z32 * C

When z32 is >= (2^32)/C, z32 * C overflows.

Diff Detail

Event Timeline

stephan.yichao.zhao requested review of this revision.Aug 24 2020, 5:47 PM
MaskRay accepted this revision.EditedAug 24 2020, 5:53 PM

LGTM. This only affects very large bitcode files. I don't know how to create a reasonable small test for this. Worth waiting one day or so before committing to give others some time to respond.

This revision is now accepted and ready to land.Aug 24 2020, 5:53 PM
MaskRay added inline comments.Aug 24 2020, 5:54 PM
llvm/lib/Bitstream/Reader/BitstreamReader.cpp
190–191

const size_t while you are updating it

addressed comments

stephan.yichao.zhao marked an inline comment as done.Aug 24 2020, 7:14 PM