Skip to content

Commit

Permalink
add validation for incorrect blob writing (#12758)
Browse files Browse the repository at this point in the history
  • Loading branch information
ivanmorozov333 authored Dec 19, 2024
1 parent fe6248f commit 737b0d5
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 0 deletions.
22 changes: 22 additions & 0 deletions ydb/core/tx/columnshard/common/blob.h
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,28 @@ struct TBlobRange {

explicit TBlobRange(const TUnifiedBlobId& blobId = TUnifiedBlobId(), ui32 offset = 0, ui32 size = 0);

static TConclusionStatus Validate(const std::vector<TUnifiedBlobId>& blobIds, const TBlobRangeLink16& range) {
if (blobIds.size() <= range.GetBlobIdxVerified()) {
return TConclusionStatus::Fail(
"incorrect blob index: " + ::ToString(range.GetBlobIdxVerified()) + " in " + ::ToString(blobIds.size()) + " elements");
}
return Validate(blobIds[range.GetBlobIdxVerified()], range);
}

static TConclusionStatus Validate(const TUnifiedBlobId& blobId, const TBlobRangeLink16& range) {
if (!range.GetSize()) {
return TConclusionStatus::Fail("zero range size");
}
if (blobId.BlobSize() <= range.GetOffset()) {
return TConclusionStatus::Fail("too big offset for blob: " + ::ToString(range.GetOffset()) + " in " + ::ToString(blobId.BlobSize()));
}
if (blobId.BlobSize() < range.GetOffset() + range.GetSize()) {
return TConclusionStatus::Fail("too big right border for blob: " + ::ToString(range.GetOffset()) + " + " +
::ToString(range.GetSize()) + " in " + ::ToString(blobId.BlobSize()));
}
return TConclusionStatus::Success();
}

static TBlobRange FromBlobId(const TUnifiedBlobId& blobId) {
return TBlobRange(blobId, 0, blobId.BlobSize());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@ void TPortionAccessorConstructor::ChunksValidation() const {
} else {
std::set<ui32> blobIdxs;
for (auto&& i : Records) {
TBlobRange::Validate(PortionInfo.MetaConstructor.BlobIds, i.GetBlobRange()).Validate();
blobIdxs.emplace(i.GetBlobRange().GetBlobIdxVerified());
}
for (auto&& i : Indexes) {
if (i.HasBlobRange()) {
TBlobRange::Validate(PortionInfo.MetaConstructor.BlobIds, i.GetBlobRangeVerified()).Validate();
blobIdxs.emplace(i.GetBlobRangeVerified().GetBlobIdxVerified());
}
}
Expand Down
2 changes: 2 additions & 0 deletions ydb/core/tx/columnshard/engines/portions/data_accessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -643,10 +643,12 @@ void TPortionDataAccessor::FullValidation() const {
PortionInfo->FullValidation();
std::set<ui32> blobIdxs;
for (auto&& i : GetRecordsVerified()) {
TBlobRange::Validate(PortionInfo->GetMeta().GetBlobIds(), i.GetBlobRange()).Validate();
blobIdxs.emplace(i.GetBlobRange().GetBlobIdxVerified());
}
for (auto&& i : GetIndexesVerified()) {
if (auto bRange = i.GetBlobRangeOptional()) {
TBlobRange::Validate(PortionInfo->GetMeta().GetBlobIds(), *bRange).Validate();
blobIdxs.emplace(bRange->GetBlobIdxVerified());
}
}
Expand Down
3 changes: 3 additions & 0 deletions ydb/core/tx/columnshard/engines/portions/meta.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ struct TPortionMeta {
TSnapshot RecordSnapshotMax;

void FullValidation() const {
for (auto&& i : BlobIds) {
AFL_VERIFY(i.BlobSize());
}
AFL_VERIFY(BlobIds.size());
AFL_VERIFY(RecordsCount);
AFL_VERIFY(ColumnRawBytes);
Expand Down

0 comments on commit 737b0d5

Please sign in to comment.