Index: lib/IR/GCOV.cpp =================================================================== --- lib/IR/GCOV.cpp +++ lib/IR/GCOV.cpp @@ -247,10 +247,22 @@ /// readGCDA - Read a function from the GCDA buffer. Return false if an error /// occurs. bool GCOVFunction::readGCDA(GCOVBuffer &Buff, GCOV::GCOVVersion Version) { - uint32_t Dummy; - if (!Buff.readInt(Dummy)) + uint32_t HeaderLength; + if (!Buff.readInt(HeaderLength)) return false; // Function header length + uint32_t MinHeaderLength = 2; + + if (Version != GCOV::V402) { + MinHeaderLength++; // CfgChecksum + } + + if (HeaderLength < MinHeaderLength) { + errs() << "Function header is invalid: expected " << MinHeaderLength + << " words, got " << HeaderLength << " (in " << Name << ").\n"; + return false; + } + uint32_t GCDAIdent; if (!Buff.readInt(GCDAIdent)) return false; @@ -280,13 +292,15 @@ } } - StringRef GCDAName; - if (!Buff.readString(GCDAName)) - return false; - if (Name != GCDAName) { - errs() << "Function names do not match: " << Name << " != " << GCDAName - << ".\n"; - return false; + if (MinHeaderLength < HeaderLength) { + StringRef GCDAName; + if (!Buff.readString(GCDAName)) + return false; + if (Name != GCDAName) { + errs() << "Function names do not match: " << Name << " != " << GCDAName + << ".\n"; + return false; + } } if (!Buff.readArcTag()) {