From ad0bedd148e4263cf232f9b89371132c7524e847 Mon Sep 17 00:00:00 2001 From: Siyang Tang Date: Fri, 29 Nov 2024 17:04:50 +0800 Subject: [PATCH] [fix](meta-service) Avoid rowset meta exceeds 2G result in protobuf fatal --- cloud/src/meta-service/meta_service.cpp | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/cloud/src/meta-service/meta_service.cpp b/cloud/src/meta-service/meta_service.cpp index 4f374832925dd7..148ee0d9d862ed 100644 --- a/cloud/src/meta-service/meta_service.cpp +++ b/cloud/src/meta-service/meta_service.cpp @@ -1310,15 +1310,24 @@ void internal_get_rowset(Transaction* txn, int64_t start, int64_t end, while (it->has_next()) { auto [k, v] = it->next(); - auto rs = response->add_rowset_meta(); + auto* rs = response->add_rowset_meta(); + auto byte_size = rs->ByteSizeLong(); + if (byte_size + v.size() > std::numeric_limits::max()) { + code = MetaServiceCode::PROTOBUF_PARSE_ERR; + msg = "rowset meta exceeded 2G, unable to serialize"; + LOG(WARNING) << msg << " key=" << hex(k); + return; + } if (!rs->ParseFromArray(v.data(), v.size())) { code = MetaServiceCode::PROTOBUF_PARSE_ERR; - msg = "malformed rowset meta, unable to deserialize"; + msg = "malformed rowset meta, unable to serialize"; LOG(WARNING) << msg << " key=" << hex(k); return; } ++num_rowsets; - if (!it->has_next()) key0 = k; + if (!it->has_next()) { + key0 = k; + } } key0.push_back('\x00'); // Update to next smallest key for iteration } while (it->more());