-
Notifications
You must be signed in to change notification settings - Fork 1.7k
fix: preserve value in t:base64Decode when input is not valid base64 #3533
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
base: v3/master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -29,7 +29,7 @@ class Base64 { | |
| static std::string encode(const std::string& data); | ||
|
|
||
| static std::string decode(const std::string& data, bool forgiven); | ||
| static std::string decode(const std::string& data); | ||
| static bool decode(const std::string& data, std::string &out); | ||
| static std::string decode_forgiven(const std::string& data); | ||
|
Comment on lines
31
to
33
|
||
|
|
||
| static void decode_forgiven_engine(unsigned char *plain_text, | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Base64::decode(const std::string&, std::string&)usesstrlen(data.c_str())for the input length. Sincedatais astd::string, this will truncate at the first embedded NUL and can mis-handle binary data; it’s also unnecessary work. Prefer usingdata.size()(anddata.data()if you don’t need a NUL terminator) for the length passed to mbedtls.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Kept strlen intentionally to preserve the original decode() behavior. Existing test case with embedded NUL depends on truncation at first NUL.