[PATCH] D110365: [llvm][profile] Do not read padding when printing build IDs
Leonard Chan via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Sep 23 14:18:27 PDT 2021
leonardchan updated this revision to Diff 374668.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D110365/new/
https://reviews.llvm.org/D110365
Files:
llvm/lib/ProfileData/InstrProfReader.cpp
Index: llvm/lib/ProfileData/InstrProfReader.cpp
===================================================================
--- llvm/lib/ProfileData/InstrProfReader.cpp
+++ llvm/lib/ProfileData/InstrProfReader.cpp
@@ -527,8 +527,24 @@
OS << "Binary IDs: \n";
const uint8_t *BI = BinaryIdsStart;
- while (BI < BinaryIdsStart + BinaryIdsSize) {
- uint64_t BinaryIdLen = swap(*reinterpret_cast<const uint64_t *>(BI));
+ const uint8_t *BIEnd = BinaryIdsStart + BinaryIdsSize;
+ while (BI < BIEnd) {
+ uint64_t BinaryIdLen = 0;
+ auto Remaining = BIEnd - BI;
+
+ // If we do not have enough to read a uint64_t, then this remaining data
+ // must be zero-padding. If it's not padded, then the data must be corrupted
+ // somehow. In case of misalignment, we can use memcpy() for safe reads.
+ if (Remaining < sizeof(BinaryIdLen)) {
+ memcpy(&BinaryIdLen, BI, Remaining);
+ if (!BinaryIdLen)
+ return success();
+ return make_error<InstrProfError>(instrprof_error::malformed);
+ }
+
+ memcpy(&BinaryIdLen, BI, sizeof(BinaryIdLen));
+ BinaryIdLen = swap(BinaryIdLen);
+
// Increment by binary id length data type size.
BI += sizeof(BinaryIdLen);
if (BI > (const uint8_t *)DataBuffer->getBufferEnd())
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D110365.374668.patch
Type: text/x-patch
Size: 1262 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210923/b862b931/attachment.bin>
More information about the llvm-commits
mailing list