diff options
author | Trevor Norris <trev.norris@gmail.com> | 2013-05-20 12:35:31 -0700 |
---|---|---|
committer | Trevor Norris <trev.norris@gmail.com> | 2013-05-20 13:40:58 -0700 |
commit | d5d5170c359fc96f36650cdd9b84cbb013c33735 (patch) | |
tree | 82d048b7fc9fffe3f7ddca5706e83c33943388e7 /src/string_bytes.cc | |
parent | f57ff787aafc0ac20b489acd1ec4dc9d09193000 (diff) | |
download | android-node-v8-d5d5170c359fc96f36650cdd9b84cbb013c33735.tar.gz android-node-v8-d5d5170c359fc96f36650cdd9b84cbb013c33735.tar.bz2 android-node-v8-d5d5170c359fc96f36650cdd9b84cbb013c33735.zip |
string_bytes: strip padding from base64 strings
Because of variations in different base64 implementation, it's been
decided to strip all padding from the end of a base64 string and
calculate its size from that.
Diffstat (limited to 'src/string_bytes.cc')
-rw-r--r-- | src/string_bytes.cc | 15 |
1 files changed, 7 insertions, 8 deletions
diff --git a/src/string_bytes.cc b/src/string_bytes.cc index 5bf0a30e27..7ba2caf93d 100644 --- a/src/string_bytes.cc +++ b/src/string_bytes.cc @@ -63,16 +63,15 @@ static inline size_t base64_decoded_size_fast(size_t size) { } static inline size_t base64_decoded_size(const char* src, size_t size) { - size = base64_decoded_size_fast(size); + if (size == 0) + return 0; - const char* end = src + size; - // check for trailing padding (1 or 2 bytes) - if (size > 0) { - if (end[-1] == '=') size--; - if (size > 0 && end[-2] == '=') size--; - } + if (src[size - 1] == '=') + size--; + if (size > 0 && src[size - 1] == '=') + size--; - return size; + return base64_decoded_size_fast(size); } |