Repository: mesos Updated Branches: refs/heads/1.5.x 9840ae195 -> d0b303e41
Allowed base64-decoding with whitespaces. Most base64 decoders do not fail on encountering whitespace characters as several encoders embed newlines to enforce line-width in encoded data. Review: https://reviews.apache.org/r/65696 Project: http://git-wip-us.apache.org/repos/asf/mesos/repo Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/5e1b63f7 Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/5e1b63f7 Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/5e1b63f7 Branch: refs/heads/1.5.x Commit: 5e1b63f7a54e25fa524388a4c95f3a3deeab4394 Parents: 9840ae1 Author: Kapil Arya <ka...@mesosphere.io> Authored: Fri Feb 16 19:25:18 2018 -0500 Committer: Kapil Arya <ka...@mesosphere.io> Committed: Tue Feb 20 16:13:32 2018 -0500 ---------------------------------------------------------------------- 3rdparty/stout/include/stout/base64.hpp | 11 +++++++++++ 3rdparty/stout/tests/base64_tests.cpp | 11 ++++++++--- 2 files changed, 19 insertions(+), 3 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/mesos/blob/5e1b63f7/3rdparty/stout/include/stout/base64.hpp ---------------------------------------------------------------------- diff --git a/3rdparty/stout/include/stout/base64.hpp b/3rdparty/stout/include/stout/base64.hpp index eabc9b0..9530c68 100644 --- a/3rdparty/stout/include/stout/base64.hpp +++ b/3rdparty/stout/include/stout/base64.hpp @@ -107,6 +107,17 @@ inline Try<std::string> decode(const std::string& s, const std::string& chars) break; // Reached the padding. } + // The base RFC (https://tools.ietf.org/html/rfc4648#section-3.3) explicitly + // asks to reject non-alphabet characters including newlines and + // whitespaces. However, other specifications like MIME simply ignore + // characters outside the base alphabet ("be liberal in what you accept"). + // Further, most implementation ignore whiltespace characters when + // processing encoded data. This allows tools to delimit encoded with + // newlines or other whitespace characters for better readability, etc. + if (isspace(c)) { + continue; + } + if (!isBase64(c)) { return Error("Invalid character '" + stringify(c) + "'"); } http://git-wip-us.apache.org/repos/asf/mesos/blob/5e1b63f7/3rdparty/stout/tests/base64_tests.cpp ---------------------------------------------------------------------- diff --git a/3rdparty/stout/tests/base64_tests.cpp b/3rdparty/stout/tests/base64_tests.cpp index a6837c8..32d32d0 100644 --- a/3rdparty/stout/tests/base64_tests.cpp +++ b/3rdparty/stout/tests/base64_tests.cpp @@ -29,9 +29,14 @@ TEST(Base64Test, Decode) EXPECT_SOME_EQ("user:password", base64::decode("dXNlcjpwYXNzd29yZA=")); EXPECT_SOME_EQ("user:password", base64::decode("dXNlcjpwYXNzd29yZA")); - // Whitespace is not allowed. - EXPECT_ERROR(base64::decode("d XNlcjpwYXNzd29yZA==")); - EXPECT_ERROR(base64::decode("d\r\nXNlcjpwYXNzd29yZA==")); + // Whitespaces are allowed. + EXPECT_SOME_EQ("user:password", base64::decode("d XNlcjpwYXNzd29yZA==")); + EXPECT_SOME_EQ("user:password", base64::decode("d\tXNlcjpwYXNzd29yZA==")); + EXPECT_SOME_EQ("user:password", base64::decode("d\nXNlcjpwYXNzd29yZA==")); + EXPECT_SOME_EQ("user:password", base64::decode("d\vXNlcjpwYXNzd29yZA==")); + EXPECT_SOME_EQ("user:password", base64::decode("d\fXNlcjpwYXNzd29yZA==")); + EXPECT_SOME_EQ("user:password", base64::decode("d\rXNlcjpwYXNzd29yZA==")); + EXPECT_SOME_EQ("user:password", base64::decode("d\r\nXNlcjpwYXNzd29yZA==")); // Invalid characters. EXPECT_ERROR(base64::decode("abc("));