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

base64_enc_len should return a bigger size #22

Open
petrbrouzda opened this issue Feb 10, 2018 · 2 comments
Open

base64_enc_len should return a bigger size #22

petrbrouzda opened this issue Feb 10, 2018 · 2 comments

Comments

@petrbrouzda
Copy link

There is a commentary in sample:

// note input is consumed in this step: it will be empty afterwards
base64_encode(encoded, input, inputLen);

There is no consumption of "input" in base64_encode, is it?
But the input gets consumed.
So problem lies somewhere else.

base64_enc_len( "Hello world" ) returns 16.
And base64 encode result is "SGVsbG8gd29ybGQ=", which is 16 characters, OK?
But this doesn't include terminating \0.
So memory gets overwritten.

  • input* is placed to address 3FFEFBE0
  • encoded* is placed to address 3FFEFBD0
  • so nul-terminator of "encoded" overwrites the first byte of input
  • so input seems to be consumed.

Fix is easy:

int base64_enc_len(int plainLen) {
return ((plainLen + 2 - ((plainLen + 2) % 3)) / 3 * 4)+1;
}

@petrbrouzda
Copy link
Author

base64_dec_len has the same problem.

@palto42
Copy link

palto42 commented May 6, 2018

I faced the same issue and identified two issues which I fixed in the example code, see pull request #23
See also my #12 (comment)

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