[tbb-commits] [tor-browser] 07/08: Bug 1792041 - Add a value for DEL to kBase64URLDecodeTable and have static asserts for lookup tables' length. r=xpcom-reviewers, nika a=RyanVM

gitolite role git at cupani.torproject.org
Thu Oct 20 14:41:33 UTC 2022


This is an automated email from the git hooks/post-receive script.

richard pushed a commit to branch tor-browser-91.13.0esr-11.5-1
in repository tor-browser.

commit 58b189015a443ed8240317710b349bb277a0ec15
Author: Jens Stutte <jstutte at mozilla.com>
AuthorDate: Thu Sep 29 21:56:28 2022 +0000

    Bug 1792041 - Add a value for DEL to kBase64URLDecodeTable and have static asserts for lookup tables' length. r=xpcom-reviewers,nika a=RyanVM
    
    Differential Revision: https://phabricator.services.mozilla.com/D158239
---
 xpcom/io/Base64.cpp | 24 +++++++++++++-----------
 1 file changed, 13 insertions(+), 11 deletions(-)

diff --git a/xpcom/io/Base64.cpp b/xpcom/io/Base64.cpp
index d7a07a102920..d490e4120a2b 100644
--- a/xpcom/io/Base64.cpp
+++ b/xpcom/io/Base64.cpp
@@ -276,26 +276,23 @@ static const uint8_t kBase64DecodeTable[] = {
   /* 112 */ 41, 42, 43, 44, 45, 46, 47, 48,
   /* 120 */ 49, 50, 51, 255, 255, 255, 255, 255,
 };
+static_assert(mozilla::ArrayLength(kBase64DecodeTable) == 0x80);
 // clang-format on
 
 template <typename T>
 [[nodiscard]] bool Base64CharToValue(T aChar, uint8_t* aValue) {
-  static const size_t mask = 0x7f;
-  static_assert(
-      (mask + 1) == sizeof(kBase64DecodeTable) / sizeof(kBase64DecodeTable[0]),
-      "wrong mask");
   size_t index = static_cast<uint8_t>(aChar);
-
-  if (index & ~mask) {
+  if (index >= mozilla::ArrayLength(kBase64DecodeTable)) {
+    *aValue = 255;
     return false;
   }
-  *aValue = kBase64DecodeTable[index & mask];
-
+  *aValue = kBase64DecodeTable[index];
   return *aValue != 255;
 }
 
 static const char kBase64URLAlphabet[] =
     "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_";
+static_assert(mozilla::ArrayLength(kBase64URLAlphabet) == 0x41);
 
 // Maps an encoded character to a value in the Base64 URL alphabet, per
 // RFC 4648, Table 2. Invalid input characters map to UINT8_MAX.
@@ -318,14 +315,19 @@ static const uint8_t kBase64URLDecodeTable[] = {
   255,
   26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41,
   42, 43, 44, 45, 46, 47, 48, 49, 50, 51, /* a - z */
-  255, 255, 255, 255,
+  255, 255, 255, 255, 255,
 };
+static_assert(mozilla::ArrayLength(kBase64URLDecodeTable) == 0x80);
 // clang-format on
 
 bool Base64URLCharToValue(char aChar, uint8_t* aValue) {
   uint8_t index = static_cast<uint8_t>(aChar);
-  *aValue = kBase64URLDecodeTable[index & 0x7f];
-  return (*aValue != 255) && !(index & ~0x7f);
+  if (index >= mozilla::ArrayLength(kBase64URLDecodeTable)) {
+    *aValue = 255;
+    return false;
+  }
+  *aValue = kBase64URLDecodeTable[index];
+  return *aValue != 255;
 }
 
 }  // namespace

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the tbb-commits mailing list