This is an archive of the discontinued LLVM Phabricator instance.

[BitcodeReader] Validate OpNum, before accessing Record array.
ClosedPublic

Authored by fhahn on Jul 10 2019, 9:19 AM.

Details

Summary

Currently invalid bitcode files can cause a crash, when OpNum exceeds
the number of elements in Record, like in the attached bitcode file.

The test case was generated by clusterfuzz: https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=15698

Diff Detail

Repository
rL LLVM

Event Timeline

fhahn created this revision.Jul 10 2019, 9:19 AM
Herald added a project: Restricted Project. · View Herald TranscriptJul 10 2019, 9:19 AM
jfb added inline comments.Jul 10 2019, 9:42 AM
llvm/lib/Bitcode/Reader/BitcodeReader.cpp
4169 ↗(On Diff #208986)

Could you provide more info than "invalid record"?

fhahn marked an inline comment as done.Jul 10 2019, 10:01 AM
fhahn added inline comments.
llvm/lib/Bitcode/Reader/BitcodeReader.cpp
4169 ↗(On Diff #208986)

Sure, although I am not sure what level of detail would be appropriate, as the error itself does not provide any context to the user besides the message.

How about Invalid record: operand number exceeded available operands?

jfb added inline comments.Jul 10 2019, 10:06 AM
llvm/lib/Bitcode/Reader/BitcodeReader.cpp
4169 ↗(On Diff #208986)

SGTM

fhahn updated this revision to Diff 209010.Jul 10 2019, 10:19 AM

Improve error message.

jfb accepted this revision.Jul 10 2019, 10:24 AM
This revision is now accepted and ready to land.Jul 10 2019, 10:24 AM
This revision was automatically updated to reflect the committed changes.
fhahn added a comment.Jul 11 2019, 4:05 AM

I've reverted the patch, because the bitcode file caused an out-of-memory error on a builder.

I think there is another problem with the bitcode file, which causes large allocations. I've seen something similar in other cases generated by cluster fuzz, which set the number of variables or something in the header to a very large number, causing large up-front allocations for an invalid file. I'll take a look.