From 0439dcfa7a5215cc74a8e254a28eadace6a524b7 Mon Sep 17 00:00:00 2001 From: Nik Bougalis Date: Mon, 4 Jun 2018 16:34:10 -0700 Subject: [PATCH] Fix a corner case when decoding base64: Under some corner cases, the base64 decoder would not allocate enough memory, which could result in spurious errors. Acknowledgements: Ripple thanks Guido Vranken for originally noticing this issue and responsibly disclosing it to Ripple. Bug Bounties and Responsible Disclosures: We welcome reviews of the rippled code and urge researchers to responsibly disclose any issues that they may find. For more on Ripple's Bug Bounty program, please visit: https://ripple.com/bug-bounty --- src/beast/include/beast/core/detail/base64.hpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/beast/include/beast/core/detail/base64.hpp b/src/beast/include/beast/core/detail/base64.hpp index 31b426a61e..9d29ca78b8 100644 --- a/src/beast/include/beast/core/detail/base64.hpp +++ b/src/beast/include/beast/core/detail/base64.hpp @@ -96,8 +96,7 @@ inline std::size_t constexpr decoded_size(std::size_t n) { - return n / 4 * 3; // requires n&3==0, smaller - //return 3 * n / 4; + return ((n / 4) * 3) + 2; } /** Encode a series of octets as a padded, base64 string.