diff options
author | alexnick <alexnick@ydb.tech> | 2023-06-08 11:16:45 +0300 |
---|---|---|
committer | alexnick <alexnick@ydb.tech> | 2023-06-08 11:16:45 +0300 |
commit | d36ea3261aec600e1ffe517e3c95586e3f2905aa (patch) | |
tree | 6a7490c1d470fb41d5e04df521ad7004bcaa066f | |
parent | d07763867d1aa41dadd045c247c3ee172391afad (diff) | |
download | ydb-d36ea3261aec600e1ffe517e3c95586e3f2905aa.tar.gz |
test and fix for out of bound array accessing
test and fix for accessing out of bound array values
-rw-r--r-- | ydb/core/tablet/private/aggregated_counters.cpp | 3 | ||||
-rw-r--r-- | ydb/core/tablet/tablet_counters_aggregator_ut.cpp | 6 |
2 files changed, 8 insertions, 1 deletions
diff --git a/ydb/core/tablet/private/aggregated_counters.cpp b/ydb/core/tablet/private/aggregated_counters.cpp index 0416117475f..f4d0424a261 100644 --- a/ydb/core/tablet/private/aggregated_counters.cpp +++ b/ydb/core/tablet/private/aggregated_counters.cpp @@ -602,7 +602,8 @@ void TAggregatedLabeledCounters::FromProto( const NKikimrLabeledCounters::TTabletLabeledCounters& labeledCounters) const { for (const auto& counter : labeledCounters.GetLabeledCounter()) { const ui32 nameId{counter.GetNameId()}; - if (strlen(Names[nameId]) != 0) { + + if (nameId < Size() && strlen(Names[nameId]) != 0) { // TODO: ASDFGS if CT_TIMELAG -> ctx.Now() - counters.GetValue const bool derived = counter.GetType() == TLabeledCounterOptions::CT_DERIV; auto namedCounter = group->GetNamedCounter("name", Names[nameId], derived); diff --git a/ydb/core/tablet/tablet_counters_aggregator_ut.cpp b/ydb/core/tablet/tablet_counters_aggregator_ut.cpp index f94a11f898f..8d9318696c1 100644 --- a/ydb/core/tablet/tablet_counters_aggregator_ut.cpp +++ b/ydb/core/tablet/tablet_counters_aggregator_ut.cpp @@ -918,6 +918,12 @@ Y_UNIT_TEST_SUITE(TTabletLabeledCountersAggregator) { UNIT_ASSERT_VALUES_EQUAL(pqCounters->GetAggregatedPerTablets().GetLabeledCounter(0).value(), 63); UNIT_ASSERT_VALUES_EQUAL(pqCounters->GetAggregatedPerTablets().GetLabeledCounter(1).value(), 11); + auto additional = pqCounters->MutableAggregatedPerTablets()->AddLabeledCounter(); + additional->SetNameId(1000); + additional->SetValue(13); + additional->SetType(TLabeledCounterOptions::CT_SIMPLE); + additional->SetAggregateFunc(TLabeledCounterOptions::EAF_SUM); + PQCounters.FromProto(counters); } } |