Skip to content

Commit 22351c6

Browse files
[CAS] Fix an off-by-one error in CAS validation
Fix a false positive in invalid CAS detection that when the last data stored in CAS just fits inside the DataPool, validation is erroneously think the data stored pass the end of the storage. The error happens when the size of the data is alignment - 1, as the null termination padding will make the end of the data matches the end of the data pool. rdar://150386374
1 parent 4b9d0c4 commit 22351c6

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

llvm/lib/CAS/OnDiskGraphDB.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -966,7 +966,7 @@ Error OnDiskGraphDB::validate(bool Deep, HashingFuncT Hasher) const {
966966
llvm_unreachable("already handled");
967967
case TrieRecord::StorageKind::DataPool: {
968968
auto DataRecord = DataRecordHandle::get(DataPool.beginData(D.Offset));
969-
if (DataRecord.getTotalSize() + D.Offset.get() >= DataPool.size())
969+
if (DataRecord.getTotalSize() + D.Offset.get() > DataPool.size())
970970
return dataError("data record span passed the end of the data pool");
971971
for (auto InternRef : DataRecord.getRefs()) {
972972
auto Index = getIndexProxyFromRef(InternRef);

llvm/test/tools/llvm-cas/validation.test

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
RUN: rm -rf %t
22
RUN: mkdir %t
33

4+
RUN: truncate -s 7 %t/file
5+
RUN: cat %t/file | \
6+
RUN: llvm-cas --cas %t/cas --make-blob \
7+
RUN: --data -
8+
RUN: llvm-cas --cas %t/cas --validate --check-hash
9+
410
RUN: llvm-cas --cas %t/cas --ingest %S/Inputs > %t/cas.id
511
RUN: llvm-cas --cas %t/cas --validate
612
RUN: llvm-cas --cas %t/cas --validate --check-hash

0 commit comments

Comments
 (0)