Skip to content

Commit 1cb3c52

Browse files
committed
chore: don't increase level in container values
1 parent 3be4410 commit 1cb3c52

File tree

2 files changed

+12
-23
lines changed

2 files changed

+12
-23
lines changed

google/cloud/bigtable/value.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -389,13 +389,13 @@ Status TypeAndMapValuesMatch(google::bigtable::v2::Type const& type,
389389
auto map_value = val.array_value().values(1);
390390
// NOLINTNEXTLINE(misc-no-recursion)
391391
auto key_match_result =
392-
Value::TypeAndValuesMatch(key_type, map_key, ++depth);
392+
Value::TypeAndValuesMatch(key_type, map_key, depth);
393393
if (!key_match_result.ok()) {
394394
return key_match_result;
395395
}
396396
// NOLINTNEXTLINE(misc-no-recursion)
397397
auto value_match_result =
398-
Value::TypeAndValuesMatch(value_type, map_value, ++depth);
398+
Value::TypeAndValuesMatch(value_type, map_value, depth);
399399
if (!value_match_result.ok()) {
400400
return value_match_result;
401401
}
@@ -425,7 +425,7 @@ Status TypeAndStructValuesMatch(google::bigtable::v2::Type const& type,
425425
for (int i = 0; i < fields.size(); ++i) {
426426
auto const& f1 = fields.Get(i);
427427
auto const& v = values[i];
428-
auto match_result = Value::TypeAndValuesMatch(f1.type(), v, ++depth);
428+
auto match_result = Value::TypeAndValuesMatch(f1.type(), v, depth);
429429
if (!match_result.ok()) {
430430
return match_result;
431431
}

google/cloud/bigtable/value_test.cc

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2051,30 +2051,19 @@ TEST(Value, TypeAndValuesMatchDepthExceeded) {
20512051
std::string type_text = "int64_type {}";
20522052
std::string value_text = "int_value: 1";
20532053

2054-
// Each layer of struct nesting increases the depth count. The initial call is
2055-
// at depth 1. With the current implementation, each level of nesting
2056-
// increases the depth by 2. To exceed the limit of 10, we need 5 levels of
2057-
// nesting, which will result in a call with depth 11.
2058-
for (int i = 0; i < 5; ++i) {
2059-
type_text =
2060-
absl::Substitute("struct_type { fields { type { $0 } } }", type_text);
2061-
value_text = absl::Substitute("array_value { values { $0 } }", value_text);
2062-
}
2063-
2064-
TestTypeAndValuesMatch(
2065-
type_text, value_text,
2066-
internal::InternalError("Nested value depth exceeds 10 levels"));
2067-
2068-
// Verify that nesting up to the limit is fine. 4 levels of nesting will
2069-
// result in a maximum depth of 9.
2070-
type_text = "int64_type {}";
2071-
value_text = "int_value: 1";
2072-
for (int i = 0; i < 4; ++i) {
2054+
// Test that exactly 10 levels does not cause a depth exceeded error.
2055+
for (int level = 1; level < 12; ++level) {
2056+
if (level <= 10) {
2057+
TestTypeAndValuesMatch(type_text, value_text, Status{});
2058+
} else {
2059+
TestTypeAndValuesMatch(
2060+
type_text, value_text,
2061+
internal::InternalError("Nested value depth exceeds 10 levels"));
2062+
}
20732063
type_text =
20742064
absl::Substitute("struct_type { fields { type { $0 } } }", type_text);
20752065
value_text = absl::Substitute("array_value { values { $0 } }", value_text);
20762066
}
2077-
TestTypeAndValuesMatch(type_text, value_text, Status{});
20782067
}
20792068

20802069
} // namespace

0 commit comments

Comments
 (0)