-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
C++ can read !!binary into vector<byte>
- Loading branch information
1 parent
12a08ee
commit 2af36ef
Showing
7 changed files
with
243 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
tools/workspace/yaml_cpp_internal/patches/upstream/b64_decode_failure_is_empty.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
DecodeBase64 will return an empty result in one of three circumstances: | ||
- The input is an empty string. | ||
- The input is nothing but whitespace (a functionally empty string). | ||
- The input has an invalid character. | ||
|
||
However, it doesn't have the proper number of encoding characters (a multiple of | ||
4), instead of reporting an error, it simply returns a truncated result with no | ||
hint of any error. | ||
|
||
This changes the function to detect the lack of sufficient data and signals by | ||
returning an empty string. This gives the caller enough information to infer | ||
a problem (and even the cause). | ||
|
||
|
||
--- src/binary.cpp | ||
+++ src/binary.cpp | ||
@@ -74,7 +74,8 @@ std::vector<unsigned char> DecodeBase64(const std::string &input) { | ||
unsigned char *out = &ret[0]; | ||
|
||
unsigned value = 0; | ||
- for (std::size_t i = 0, cnt = 0; i < input.size(); i++) { | ||
+ std::size_t cnt = 0; | ||
+ for (std::size_t i = 0; i < input.size(); i++) { | ||
if (std::isspace(static_cast<unsigned char>(input[i]))) { | ||
// skip newlines | ||
continue; | ||
@@ -90,9 +91,14 @@ std::vector<unsigned char> DecodeBase64(const std::string &input) { | ||
*out++ = value >> 8; | ||
if (input[i] != '=') | ||
*out++ = value; | ||
+ cnt = 0; | ||
+ } else { | ||
+ ++cnt; | ||
} | ||
- ++cnt; | ||
} | ||
+ // An invalid number of characters were encountered. | ||
+ if (cnt != 0) | ||
+ return ret_type(); | ||
|
||
ret.resize(out - &ret[0]); | ||
return ret; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters