wasphin commented on code in PR #3658:
URL: https://github.com/apache/brpc/pull/3658#discussion_r4378410753
##########
test/brpc_checksum_unittest.cpp:
##########
@@ -50,6 +51,34 @@ TEST_F(ChecksumAttachmentTest,
verify_succeeds_when_body_only) {
EXPECT_TRUE(brpc::policy::Crc32cVerify(verify_in));
}
+TEST_F(ChecksumAttachmentTest, verify_rejects_invalid_checksum_lengths) {
+ brpc::Controller cntl;
+ butil::IOBuf body;
+ body.append("request body");
+ brpc::ChecksumIn in{&body, &cntl, nullptr};
+ brpc::policy::Crc32cCompute(in);
+ brpc::ControllerPrivateAccessor accessor(&cntl);
+ const std::string valid = accessor.checksum_value();
+ ASSERT_EQ(sizeof(uint32_t), valid.size());
+
+ logging::StringSink logs;
+ {
+ logging::LogSink* previous = logging::SetLogSink(&logs);
+ BUTIL_SCOPE_EXIT { logging::SetLogSink(previous); };
+ for (size_t size = 0; size <= 8; ++size) {
+ if (size == valid.size()) {
+ continue;
+ }
+ const std::string invalid(size, '\0');
+ accessor.set_checksum_value(invalid.data(), invalid.size());
+ EXPECT_FALSE(brpc::policy::Crc32cVerify(in)) << "size=" << size;
+ }
+ accessor.set_checksum_value(valid.data(), valid.size());
+ EXPECT_TRUE(brpc::policy::Crc32cVerify(in));
+ }
+ EXPECT_EQ(std::string::npos, logs.find("Check failed: val.size()"));
Review Comment:
Fixed in dd5cae54. The logging capture and log assertion are guarded by #if
!BRPC_WITH_GLOG, while checksum assertions remain enabled for both backends.
All 10 default-backend tests pass. Compilation with real glog headers and
BRPC_WITH_GLOG=1 passes; the original version reproduces the compile error.
Full glog runtime tests were not run.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]