Commit 91b27188 authored by ch.dumez@samsung.com's avatar ch.dumez@samsung.com

window.atob() returns wrong value when given a string container only white spaces

window.atob() returns wrong value when given a string container only white
spaces. The reason was that base64DecodeInternal() was calling Vector::grow()
before the loop but failed to call Vector::shrink() in case of early return.

R=
BUG=357332

Review URL: https://codereview.chromium.org/215833002

git-svn-id: svn://svn.chromium.org/blink/trunk@170264 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent 22f4bf36
......@@ -49,6 +49,7 @@ PASS window.atob("zzz===") threw exception InvalidCharacterError: Failed to exec
PASS window.atob("zzz====") threw exception InvalidCharacterError: Failed to execute 'atob' on 'Window': The string to be decoded is not correctly encoded..
PASS window.atob("zzz=====") threw exception InvalidCharacterError: Failed to execute 'atob' on 'Window': The string to be decoded is not correctly encoded..
PASS window.atob("zzzz") is "Ï<ó"
PASS atob(" ") is ""
PASS window.atob("zzzzz") threw exception InvalidCharacterError: Failed to execute 'atob' on 'Window': The string to be decoded is not correctly encoded..
PASS window.atob("z=zz") threw exception InvalidCharacterError: Failed to execute 'atob' on 'Window': The string to be decoded is not correctly encoded..
PASS window.atob("=") threw exception InvalidCharacterError: Failed to execute 'atob' on 'Window': The string to be decoded is not correctly encoded..
......
......@@ -63,6 +63,7 @@ shouldThrow('window.atob("zzz===")'); // excess pad characters.
shouldThrow('window.atob("zzz====")'); // excess pad characters.
shouldThrow('window.atob("zzz=====")'); // excess pad characters.
shouldBeEqualToString('window.atob("zzzz")', 'Ï\u003Có');
shouldBeEqualToString('atob(" ")', ''); // whitespace only.
shouldThrow('window.atob("zzzzz")');
shouldThrow('window.atob("z=zz")');
shouldThrow('window.atob("=")');
......
......@@ -149,22 +149,34 @@ static inline bool base64DecodeInternal(const T* data, unsigned length, Vector<c
unsigned equalsSignCount = 0;
unsigned outLength = 0;
bool hadError = false;
for (unsigned idx = 0; idx < length; ++idx) {
unsigned ch = data[idx];
if (ch == '=') {
++equalsSignCount;
// There should never be more than 2 padding characters.
if (policy == Base64ValidatePadding && equalsSignCount > 2)
return false;
if (policy == Base64ValidatePadding && equalsSignCount > 2) {
hadError = true;
break;
}
} else if (('0' <= ch && ch <= '9') || ('A' <= ch && ch <= 'Z') || ('a' <= ch && ch <= 'z') || ch == '+' || ch == '/') {
if (equalsSignCount)
return false;
if (equalsSignCount) {
hadError = true;
break;
}
out[outLength++] = base64DecMap[ch];
} else if (!shouldIgnoreCharacter || !shouldIgnoreCharacter(ch)) {
return false;
hadError = true;
break;
}
}
if (outLength < out.size())
out.shrink(outLength);
if (hadError)
return false;
if (!outLength)
return !equalsSignCount;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment