This is an automated email from the ASF dual-hosted git repository.
wwbmmm pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/brpc.git
The following commit(s) were added to refs/heads/master by this push:
new 925e3df50 Align RVV Base64 input validation with the scalar decoder
(#3662)
925e3df50 is described below
commit 925e3df50cb44466743dbb1c281d230d697b63b7
Author: Xiaofeng Wang <[email protected]>
AuthorDate: Sat Nov 7 17:01:11 2026 +0800
Align RVV Base64 input validation with the scalar decoder (#3662)
---
src/butil/third_party/modp_b64/modp_b64_rvv.cc | 11 +++++++----
test/base64_unittest.cc | 12 ++++++++++++
2 files changed, 19 insertions(+), 4 deletions(-)
diff --git a/src/butil/third_party/modp_b64/modp_b64_rvv.cc
b/src/butil/third_party/modp_b64/modp_b64_rvv.cc
index 10fd8847d..4c7617791 100644
--- a/src/butil/third_party/modp_b64/modp_b64_rvv.cc
+++ b/src/butil/third_party/modp_b64/modp_b64_rvv.cc
@@ -150,11 +150,14 @@ size_t rvv_modp_b64_decode(char* dest, const char* src,
size_t len)
{
if (len == 0) return 0;
- /* Strip trailing '=' padding (up to 2 chars for valid base64) */
- while (len > 0 && src[len-1] == '=') {
- len--;
+ /* Match the padded scalar decoder's length and padding rules. */
+ if (len < 4 || len % 4 != 0) return MODP_B64_RVV_ERROR;
+ if (src[len-1] == '=') {
+ --len;
+ if (src[len-1] == '=') {
+ --len;
+ }
}
- if (len == 0) return 0;
size_t i = 0;
uint8_t* p = (uint8_t*)dest;
diff --git a/test/base64_unittest.cc b/test/base64_unittest.cc
index 40a3906a9..3f4964231 100644
--- a/test/base64_unittest.cc
+++ b/test/base64_unittest.cc
@@ -24,4 +24,16 @@ TEST(Base64Test, Basic) {
EXPECT_EQ(kText, decoded);
}
+TEST(Base64Test, RejectsMalformedPaddingAndLengths) {
+ for (const char* input : {"A", "AA", "AAA", "AAAAA", "=", "====",
+ "A===", "AA======", "AA=A", "AA==AAAA"}) {
+ std::string decoded;
+ EXPECT_FALSE(butil::Base64Decode(input, &decoded)) << input;
+ }
+ for (const char* input : {"", "AA==", "AAA=", "AAAA"}) {
+ std::string decoded;
+ EXPECT_TRUE(butil::Base64Decode(input, &decoded)) << input;
+ }
+}
+
} // namespace butil
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]