Fix DecodeBase64 to reject truncated input

If the input doesn't have the proper number of encoding characters
(a multiple of 4), return an empty result.

Co-Authored-By: Sean Curtis <sean.curtis@tri.global>
This commit is contained in:
Jeremy Nimmer
2026-02-10 07:01:22 -08:00
committed by Jesse Beder
parent 2e6383d272
commit 80ea0028c7
2 changed files with 16 additions and 3 deletions

View File

@@ -12,3 +12,9 @@ TEST(BinaryTest, DecodingNoCrashOnNegative) {
const std::vector<unsigned char> &result = YAML::DecodeBase64(input);
EXPECT_TRUE(result.empty());
}
TEST(BinaryTest, DecodingTooShort) {
std::string input{90, 71, 86, 104, 90, 71, 74, 108, 90, 87, 89};
const std::vector<unsigned char> &result = YAML::DecodeBase64(input);
EXPECT_TRUE(result.empty());
}