[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

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



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

pierov pushed a commit to annotated tag FIREFOX_102_4_0esr_BUILD1
in repository tor-browser.

commit 48a0b7d3e99c5bc40ee101427ac6ad04671b92db
Author: Jens Stutte <jstutte@xxxxxxxxxxx>
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 a9c31faf6d8c..3083632348a1 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.
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits