Skip to content

Commit 97a6a7d

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 6756162 commit 97a6a7d

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

llvm/lib/CAS/OnDiskGraphDB.cpp

+1-1
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

+7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
RUN: rm -rf %t
22
RUN: mkdir %t
33

4+
# Ingest a blob which just fits inside the CAS data pool to make sure the validate passes.
5+
RUN: truncate -s 7 %t/file
6+
RUN: cat %t/file | \
7+
RUN: llvm-cas --cas %t/cas --make-blob \
8+
RUN: --data -
9+
RUN: llvm-cas --cas %t/cas --validate --check-hash
10+
411
RUN: llvm-cas --cas %t/cas --ingest %S/Inputs > %t/cas.id
512
RUN: llvm-cas --cas %t/cas --validate
613
RUN: llvm-cas --cas %t/cas --validate --check-hash

0 commit comments

Comments
 (0)