Skip to content

Commit a4e3d4c

Browse files
committed
fix: Add base64 character validation in DecodeBase64 function
1 parent 3ee89e9 commit a4e3d4c

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

src/std/base64.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,17 @@ bool DecodeBase64 ( const CSphString & sValue, CSphString & sResult )
2121
{
2222
std::string sVal = sValue.cstr();
2323

24+
// Validate base64 characters before attempting decode to avoid crashes
25+
// Base64 uses A-Z, a-z, 0-9, +, /, and = for padding
26+
if ( sVal.empty() )
27+
return false;
28+
29+
for ( char c : sVal )
30+
{
31+
if ( !((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') || (c >= '0' && c <= '9') || c == '+' || c == '/' || c == '=') )
32+
return false;
33+
}
34+
2435
using namespace boost::archive::iterators;
2536
try
2637
{

0 commit comments

Comments
 (0)