diff --git a/lib/ProfileData/InstrProfReader.cpp b/lib/ProfileData/InstrProfReader.cpp index 5c1993766aa..e333473f6f8 100644 --- a/lib/ProfileData/InstrProfReader.cpp +++ b/lib/ProfileData/InstrProfReader.cpp @@ -190,6 +190,9 @@ RawInstrProfReader::readNextHeader(const char *CurrentPos) { // garbage at the end of the file. if (CurrentPos + sizeof(RawHeader) > End) return instrprof_error::malformed; + // The writer ensures each profile is padded to start at an aligned address. + if (reinterpret_cast(CurrentPos) % alignOf()) + return instrprof_error::malformed; // The magic should have the same byte order as in the previous header. uint64_t Magic = *reinterpret_cast(CurrentPos); if (Magic != swap(getRawMagic())) diff --git a/test/tools/llvm-profdata/raw-two-profiles.test b/test/tools/llvm-profdata/raw-two-profiles.test index 3260836ba66..be78793215e 100644 --- a/test/tools/llvm-profdata/raw-two-profiles.test +++ b/test/tools/llvm-profdata/raw-two-profiles.test @@ -39,11 +39,9 @@ RUN: printf '\0\0\0\0\0' >> %t-foo-padded.profraw RUN: cat %t-bar.profraw > %t-bar-padded.profraw RUN: printf '\0\0\0\0\0' >> %t-bar-padded.profraw -RUN: cat %t-foo.profraw %t-bar.profraw > %t-nopad.profraw RUN: cat %t-foo-padded.profraw %t-bar.profraw > %t-pad-between.profraw RUN: cat %t-foo-padded.profraw %t-bar-padded.profraw > %t-pad.profraw -RUN: llvm-profdata show %t-nopad.profraw -all-functions -counts | FileCheck %s RUN: llvm-profdata show %t-pad-between.profraw -all-functions -counts | FileCheck %s RUN: llvm-profdata show %t-pad.profraw -all-functions -counts | FileCheck %s