Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem with Base64_Decode() #7412

Open
MarleenDev opened this issue Apr 11, 2024 · 1 comment
Open

Problem with Base64_Decode() #7412

MarleenDev opened this issue Apr 11, 2024 · 1 comment
Assignees

Comments

@MarleenDev
Copy link

MarleenDev commented Apr 11, 2024

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.

@anhu anhu self-assigned this Apr 11, 2024
@anhu
Copy link
Member

anhu commented Apr 11, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants