Skip to content

Commit

Permalink
base64decode should return immediately if the input is empty
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinbackhouse committed Nov 10, 2024
1 parent 6f9387c commit 1acdf0c
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/futils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ static char to_hex(char code) {

/// @brief Convert a hex character to its integer value.
static char from_hex(char ch) {
return isdigit(ch) ? ch - '0' : static_cast<char>(tolower(ch)) - 'a' + 10;
return 0xF & (isdigit(ch) ? ch - '0' : static_cast<char>(tolower(ch)) - 'a' + 10);
}

std::string urlencode(const std::string& str) {
Expand Down Expand Up @@ -168,7 +168,7 @@ int base64encode(const void* data_buf, size_t dataLength, char* result, size_t r
size_t base64decode(const char* in, char* out, size_t out_size) {
size_t result = 0;
size_t input_length = in ? ::strlen(in) : 0;
if (!in || input_length % 4 != 0)
if (!in || input_length % 4 != 0 || input_length == 0)
return result;

auto encoding_table = reinterpret_cast<const unsigned char*>(base64_encode);
Expand Down

0 comments on commit 1acdf0c

Please sign in to comment.