wolfssl icon indicating copy to clipboard operation
wolfssl copied to clipboard

Problem with Base64_Decode()

Open MarleenDev opened this issue 1 year ago • 1 comments

Version

latest

Description

When calling the Base64_Decode() function in wolfcrypt/src/coding.c to decode a short base64 encoded string, it returns BAD_FUNC_ARG. input:

  • in = "Wr8NAAEAVQAAZr9jOA=="
  • inLen= 20
  • out = our buffer containing space for 13 bytes, because the decoded length is 13
  • outLen = 13

At the start of Base64_Decode(), plainSz is calculated, which I guess is an estimate of the decoded size. Because of rounding, this becomes 19, which is then turned into (19*3+3)/4 which equals 15. This is of course greater than the outLen (15 > 13), so BAD_FUNC_ARG is returned.

The goal of this decoding is to copy the resulting bytes to a struct with a size of 13. De decoded size has 13 bytes, so I would expect it to work as-is. But because of the function requiring a 15 byte buffer, I am wondering whether I am doing something wrong, or if this is a bug. Please advise.

MarleenDev avatar Apr 11 '24 07:04 MarleenDev

Hello @MarleenDev ,

Thank you for your interest in wolfSSL. Please see https://www.wolfssl.com/documentation/manuals/wolfssl/group__Base__Encoding.html#function-base64_decode .

In the example code for this API, the comment applies:

// requires at least (sizeof(encoded) * 3 + 3) / 4 room

Can you please let us know about yourself and your project that is using wolfSSL? Here at wolfSSL we love to know about how people are using our code. Some examples would be:

  • whether this project is for personal, academic or professional interest
  • are there any institutions associated with this project?
  • where you are located?
  • what are you trying to do? What are your goals?

Any information you can provide would be greatly appreciated.

Warm regards, Anthony

anhu avatar Apr 11 '24 16:04 anhu