-
Notifications
You must be signed in to change notification settings - Fork 165
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
Decoding data containing <NUL> values #114
Comments
The return value of
I also cannot reproduce this bug with the following command line: echo -ne 'hello\0world' | bin/base64 | bin/base64 -d >/dev/null; echo $? This prints So either this is an obscure bug hiding in one of the optimized SIMD decoders, or something else is going on. Which codec are you using? Does the test suite run correctly on your machine? Can you post any code to reproduce the issue? |
I added a very quick and dirty test to do roundtrip encoding on data with |
I figured it out. My allocated buffer for encoding was not big enough, and it caused the last padding I guess the readme is missleading:
The right buffer size is probably |
TBH I think it would make sense to add two macros or inline functions to do buffer size calculations. As an added bonus it'd be way more readable than to repeat the size calculation everywhere.
While we are at it, I think a flag to encode/decode without padding would make sense, too. See also RFC4648 section 3.2. |
Agreed that it makes sense for the library to expose a macro to do the buffer size calculation. I've been hesitant to add one (or to publish the "ultimate buffer sizing formula" in the sense of the post above) because I'm not positive that all encoders will always stay within the bounds of such a buffer. The SIMD encoders write 16 bytes of output at a time. Then again, those SIMD encoders always operate on a full, guaranteed 12 bytes of input, so their output should always fit into the output buffer if it's sized according to something like the formula above. Regarding the suggestion of adding a flag to disable padding: the suggestion makes sense, but I'm wary of adding more behavioral flags at this point. I'd first like to do a comprehensive rewrite to sort out various pain points, and rethink the architecture of this library first. |
I created #116 to discuss the addition of size macros. |
It seems that if I encode then decode data containing
<NUL>
characters, the data is correctly encoded and decoded, butbase64_decode
returns 0 instead of 1. Is that the expected behavior?The text was updated successfully, but these errors were encountered: