mirror of
https://repo.dactyloidae.xyz/Dactyloidae/UXP.git
synced 2026-08-15 17:03:07 +09:00
[XPCOM] Fix Base64 off-by-one issue and safeguard against this mistake in the future.
This commit is contained in:
parent
e69b52eac1
commit
3fccd404fb
1 changed files with 9 additions and 3 deletions
|
|
@ -246,6 +246,7 @@ EncodeInputStream(nsIInputStream* aInputStream,
|
|||
|
||||
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.
|
||||
|
|
@ -267,14 +268,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);
|
||||
|
||||
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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue