Changeset 158933 in webkit


Ignore:
Timestamp:
Nov 8, 2013, 11:37:57 AM (12 years ago)
Author:
ap@apple.com
Message:

Make base64url decoding actually work
https://bugs.webkit.org/show_bug.cgi?id=124050

Reviewed by Sam Weinig.

  • wtf/text/Base64.cpp: (WTF::base64DecodeInternal): Don't hardcode knowledge about

alphabet, put it into the map.

Location:
trunk/Source/WTF
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WTF/ChangeLog

    r158848 r158933  
     12013-11-08  Alexey Proskuryakov  <ap@apple.com>
     2
     3        Make base64url decoding actually work
     4        https://bugs.webkit.org/show_bug.cgi?id=124050
     5
     6        Reviewed by Sam Weinig.
     7
     8        * wtf/text/Base64.cpp: (WTF::base64DecodeInternal): Don't hardcode knowledge about
     9        alphabet, put it into the map.
     10
    1112013-11-07  Denis Nomiyama  <d.nomiyama@samsung.com>
    212
  • trunk/Source/WTF/wtf/text/Base64.cpp

    r158628 r158933  
    3030
    3131namespace WTF {
     32
     33const char nonAlphabet = -1;
    3234
    3335static const char base64EncMap[64] = {
     
    4345
    4446static const char base64DecMap[128] = {
    45     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    46     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    47     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    48     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    49     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    50     0x00, 0x00, 0x00, 0x3E, 0x00, 0x00, 0x00, 0x3F,
     47    nonAlphabet, nonAlphabet, nonAlphabet, nonAlphabet, nonAlphabet, nonAlphabet, nonAlphabet, nonAlphabet,
     48    nonAlphabet, nonAlphabet, nonAlphabet, nonAlphabet, nonAlphabet, nonAlphabet, nonAlphabet, nonAlphabet,
     49    nonAlphabet, nonAlphabet, nonAlphabet, nonAlphabet, nonAlphabet, nonAlphabet, nonAlphabet, nonAlphabet,
     50    nonAlphabet, nonAlphabet, nonAlphabet, nonAlphabet, nonAlphabet, nonAlphabet, nonAlphabet, nonAlphabet,
     51    nonAlphabet, nonAlphabet, nonAlphabet, nonAlphabet, nonAlphabet, nonAlphabet, nonAlphabet, nonAlphabet,
     52    nonAlphabet, nonAlphabet, nonAlphabet, 0x3E, nonAlphabet, nonAlphabet, nonAlphabet, 0x3F,
    5153    0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3A, 0x3B,
    52     0x3C, 0x3D, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    53     0x00, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06,
     54    0x3C, 0x3D, nonAlphabet, nonAlphabet, nonAlphabet, nonAlphabet, nonAlphabet, nonAlphabet,
     55    nonAlphabet, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06,
    5456    0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E,
    5557    0x0F, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16,
    56     0x17, 0x18, 0x19, 0x00, 0x00, 0x00, 0x00, 0x00,
    57     0x00, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F, 0x20,
     58    0x17, 0x18, 0x19, nonAlphabet, nonAlphabet, nonAlphabet, nonAlphabet, nonAlphabet,
     59    nonAlphabet, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F, 0x20,
    5860    0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28,
    5961    0x29, 0x2A, 0x2B, 0x2C, 0x2D, 0x2E, 0x2F, 0x30,
    60     0x31, 0x32, 0x33, 0x00, 0x00, 0x00, 0x00, 0x00
     62    0x31, 0x32, 0x33, nonAlphabet, nonAlphabet, nonAlphabet, nonAlphabet, nonAlphabet
    6163};
    6264
     
    7375
    7476static const char base64URLDecMap[128] = {
    75     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    76     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    77     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    78     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    79     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    80     0x00, 0x00, 0x00, 0x00, 0x00, 0x3E, 0x00, 0x00,
     77    nonAlphabet, nonAlphabet, nonAlphabet, nonAlphabet, nonAlphabet, nonAlphabet, nonAlphabet, nonAlphabet,
     78    nonAlphabet, nonAlphabet, nonAlphabet, nonAlphabet, nonAlphabet, nonAlphabet, nonAlphabet, nonAlphabet,
     79    nonAlphabet, nonAlphabet, nonAlphabet, nonAlphabet, nonAlphabet, nonAlphabet, nonAlphabet, nonAlphabet,
     80    nonAlphabet, nonAlphabet, nonAlphabet, nonAlphabet, nonAlphabet, nonAlphabet, nonAlphabet, nonAlphabet,
     81    nonAlphabet, nonAlphabet, nonAlphabet, nonAlphabet, nonAlphabet, nonAlphabet, nonAlphabet, nonAlphabet,
     82    nonAlphabet, nonAlphabet, nonAlphabet, nonAlphabet, nonAlphabet, 0x3E, nonAlphabet, nonAlphabet,
    8183    0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3A, 0x3B,
    82     0x3C, 0x3D, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
    83     0x00, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06,
     84    0x3C, 0x3D, nonAlphabet, nonAlphabet, nonAlphabet, nonAlphabet, nonAlphabet, nonAlphabet,
     85    nonAlphabet, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06,
    8486    0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E,
    8587    0x0F, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16,
    86     0x17, 0x18, 0x19, 0x00, 0x00, 0x00, 0x00, 0x3F,
    87     0x00, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F, 0x20,
     88    0x17, 0x18, 0x19, nonAlphabet, nonAlphabet, nonAlphabet, nonAlphabet, 0x3F,
     89    nonAlphabet, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F, 0x20,
    8890    0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28,
    8991    0x29, 0x2A, 0x2B, 0x2C, 0x2D, 0x2E, 0x2F, 0x30,
    90     0x31, 0x32, 0x33, 0x00, 0x00, 0x00, 0x00, 0x00
     92    0x31, 0x32, 0x33, nonAlphabet, nonAlphabet, nonAlphabet, nonAlphabet, nonAlphabet
    9193};
    9294
     
    195197            if (policy == Base64FailOnInvalidCharacterOrExcessPadding && (length % 4 || equalsSignCount > 2))
    196198                return false;
    197         } else if (('0' <= ch && ch <= '9') || ('A' <= ch && ch <= 'Z') || ('a' <= ch && ch <= 'z') || ch == '+' || ch == '/') {
    198             if (equalsSignCount)
     199        } else {
     200            char decodedCharacter = decodeMap[ch];
     201            if (decodedCharacter != nonAlphabet) {
     202                if (equalsSignCount)
     203                    return false;
     204                out[outLength] = decodedCharacter;
     205                ++outLength;
     206            } else if (policy == Base64FailOnInvalidCharacterOrExcessPadding || policy == Base64FailOnInvalidCharacter || (policy == Base64IgnoreWhitespace && !isSpaceOrNewline(ch)))
    199207                return false;
    200             out[outLength] = decodeMap[ch];
    201             ++outLength;
    202         } else if (policy == Base64FailOnInvalidCharacterOrExcessPadding || policy == Base64FailOnInvalidCharacter || (policy == Base64IgnoreWhitespace && !isSpaceOrNewline(ch)))
    203             return false;
     208        }
    204209    }
    205210
Note: See TracChangeset for help on using the changeset viewer.