- Revision
- 153904
- Author
- [email protected]
- Date
- 2013-08-09 11:54:32 -0700 (Fri, 09 Aug 2013)
Log Message
Make atob() throw an InvalidCharacterError on excess padding characters
https://bugs.webkit.org/show_bug.cgi?id=118898
Reviewed by Darin Adler.
Source/WebCore:
According to the latest specification, window.atob() should throw an
InvalidCharacterError on excess padding characters:
http://www.whatwg.org/specs/web-apps/current-work/multipage/webappapis.html#dom-windowbase64-atob
This behavior is consistent with both Firefox, IE10 and recently Blink.
No new tests, already covered by:
fast/dom/Window/atob-btoa.html
* page/DOMWindow.cpp:
(WebCore::DOMWindow::atob):
Source/WTF:
Add a Base64FailOnInvalidCharacterOrExcessPadding value to the Base64DecodePolicy
enumeration so that the caller can request strict padding validation in addition
to strict character validation. This is needed so that we can use
WTF::base64Decode() for window.atob().
* wtf/text/Base64.cpp:
(WTF::base64DecodeInternal):
* wtf/text/Base64.h:
LayoutTests:
Update and rebaseline fast/dom/Window/atob-btoa.html now that window.atob()'s
behavior has changed and now that we throw an InvalidCharacterError on excess
pad characters.
* fast/dom/Window/atob-btoa-expected.txt:
* fast/dom/Window/atob-btoa.html:
Modified Paths
Diff
Modified: trunk/LayoutTests/ChangeLog (153903 => 153904)
--- trunk/LayoutTests/ChangeLog 2013-08-09 18:40:48 UTC (rev 153903)
+++ trunk/LayoutTests/ChangeLog 2013-08-09 18:54:32 UTC (rev 153904)
@@ -1,3 +1,17 @@
+2013-08-09 Christophe Dumez <[email protected]>
+
+ Make atob() throw an InvalidCharacterError on excess padding characters
+ https://bugs.webkit.org/show_bug.cgi?id=118898
+
+ Reviewed by Darin Adler.
+
+ Update and rebaseline fast/dom/Window/atob-btoa.html now that window.atob()'s
+ behavior has changed and now that we throw an InvalidCharacterError on excess
+ pad characters.
+
+ * fast/dom/Window/atob-btoa-expected.txt:
+ * fast/dom/Window/atob-btoa.html:
+
2013-08-09 Alexey Proskuryakov <[email protected]>
<unknown> is often dumped instead of path in test output
Modified: trunk/LayoutTests/fast/dom/Window/atob-btoa-expected.txt (153903 => 153904)
--- trunk/LayoutTests/fast/dom/Window/atob-btoa-expected.txt 2013-08-09 18:40:48 UTC (rev 153903)
+++ trunk/LayoutTests/fast/dom/Window/atob-btoa-expected.txt 2013-08-09 18:54:32 UTC (rev 153904)
@@ -36,9 +36,10 @@
PASS window.atob("zz") is "Ï"
PASS window.atob("zzz") is "Ï<"
PASS window.atob("zzz=") is "Ï<"
-PASS window.atob("zzz==") is "Ï<"
-PASS window.atob("zzz===") is "Ï<"
-PASS window.atob("zzz====") is "Ï<"
+PASS window.atob("zzz==") threw exception Error: InvalidCharacterError: DOM Exception 5.
+PASS window.atob("zzz===") threw exception Error: InvalidCharacterError: DOM Exception 5.
+PASS window.atob("zzz====") threw exception Error: InvalidCharacterError: DOM Exception 5.
+PASS window.atob("zzz=====") threw exception Error: InvalidCharacterError: DOM Exception 5.
PASS window.atob("zzzz") is "Ï<ó"
PASS window.atob("zzzzz") threw exception Error: InvalidCharacterError: DOM Exception 5.
PASS window.atob("z=zz") threw exception Error: InvalidCharacterError: DOM Exception 5.
Modified: trunk/LayoutTests/fast/dom/Window/atob-btoa.html (153903 => 153904)
--- trunk/LayoutTests/fast/dom/Window/atob-btoa.html 2013-08-09 18:40:48 UTC (rev 153903)
+++ trunk/LayoutTests/fast/dom/Window/atob-btoa.html 2013-08-09 18:54:32 UTC (rev 153904)
@@ -46,9 +46,10 @@
shouldBe('window.atob("zz")', '"Ï"');
shouldBe('window.atob("zzz")', '"Ï\u003C"');
shouldBe('window.atob("zzz=")', '"Ï\u003C"');
-shouldBe('window.atob("zzz==")', '"Ï\u003C"');
-shouldBe('window.atob("zzz===")', '"Ï\u003C"');
-shouldBe('window.atob("zzz====")', '"Ï\u003C"');
+shouldThrow('window.atob("zzz==")'); // excess pad characters.
+shouldThrow('window.atob("zzz===")'); // excess pad characters.
+shouldThrow('window.atob("zzz====")'); // excess pad characters.
+shouldThrow('window.atob("zzz=====")'); // excess pad characters.
shouldBe('window.atob("zzzz")', '"Ï\u003Có"');
shouldThrow('window.atob("zzzzz")');
shouldThrow('window.atob("z=zz")');
Modified: trunk/Source/WTF/ChangeLog (153903 => 153904)
--- trunk/Source/WTF/ChangeLog 2013-08-09 18:40:48 UTC (rev 153903)
+++ trunk/Source/WTF/ChangeLog 2013-08-09 18:54:32 UTC (rev 153904)
@@ -1,3 +1,19 @@
+2013-08-09 Christophe Dumez <[email protected]>
+
+ Make atob() throw an InvalidCharacterError on excess padding characters
+ https://bugs.webkit.org/show_bug.cgi?id=118898
+
+ Reviewed by Darin Adler.
+
+ Add a Base64FailOnInvalidCharacterOrExcessPadding value to the Base64DecodePolicy
+ enumeration so that the caller can request strict padding validation in addition
+ to strict character validation. This is needed so that we can use
+ WTF::base64Decode() for window.atob().
+
+ * wtf/text/Base64.cpp:
+ (WTF::base64DecodeInternal):
+ * wtf/text/Base64.h:
+
2013-08-07 Alex Christensen <[email protected]>
Fixed wrong definition for AppleWin port's WebGL after r153768.
Modified: trunk/Source/WTF/wtf/text/Base64.cpp (153903 => 153904)
--- trunk/Source/WTF/wtf/text/Base64.cpp 2013-08-09 18:40:48 UTC (rev 153903)
+++ trunk/Source/WTF/wtf/text/Base64.cpp 2013-08-09 18:54:32 UTC (rev 153904)
@@ -140,31 +140,35 @@
}
template<typename T>
-static inline bool base64DecodeInternal(const T* data, unsigned len, Vector<char>& out, Base64DecodePolicy policy)
+static inline bool base64DecodeInternal(const T* data, unsigned length, Vector<char>& out, Base64DecodePolicy policy)
{
out.clear();
- if (!len)
+ if (!length)
return true;
- out.grow(len);
+ out.grow(length);
- bool sawEqualsSign = false;
+ unsigned equalsSignCount = 0;
unsigned outLength = 0;
- for (unsigned idx = 0; idx < len; ++idx) {
+ for (unsigned idx = 0; idx < length; ++idx) {
unsigned ch = data[idx];
- if (ch == '=')
- sawEqualsSign = true;
- else if (('0' <= ch && ch <= '9') || ('A' <= ch && ch <= 'Z') || ('a' <= ch && ch <= 'z') || ch == '+' || ch == '/') {
- if (sawEqualsSign)
+ if (ch == '=') {
+ ++equalsSignCount;
+ // There should be no padding if length is a multiple of 4, and there
+ // should never be more than 2 padding characters.
+ if (policy == Base64FailOnInvalidCharacterOrExcessPadding && (length % 4 || equalsSignCount > 2))
return false;
+ } else if (('0' <= ch && ch <= '9') || ('A' <= ch && ch <= 'Z') || ('a' <= ch && ch <= 'z') || ch == '+' || ch == '/') {
+ if (equalsSignCount)
+ return false;
out[outLength] = base64DecMap[ch];
++outLength;
- } else if (policy == Base64FailOnInvalidCharacter || (policy == Base64IgnoreWhitespace && !isSpaceOrNewline(ch)))
+ } else if (policy == Base64FailOnInvalidCharacterOrExcessPadding || policy == Base64FailOnInvalidCharacter || (policy == Base64IgnoreWhitespace && !isSpaceOrNewline(ch)))
return false;
}
if (!outLength)
- return !sawEqualsSign;
+ return !equalsSignCount;
// Valid data is (n * 4 + [0,2,3]) characters long.
if ((outLength % 4) == 1)
Modified: trunk/Source/WTF/wtf/text/Base64.h (153903 => 153904)
--- trunk/Source/WTF/wtf/text/Base64.h 2013-08-09 18:40:48 UTC (rev 153903)
+++ trunk/Source/WTF/wtf/text/Base64.h 2013-08-09 18:54:32 UTC (rev 153904)
@@ -39,6 +39,7 @@
};
enum Base64DecodePolicy {
+ Base64FailOnInvalidCharacterOrExcessPadding,
Base64FailOnInvalidCharacter,
Base64IgnoreWhitespace,
Base64IgnoreInvalidCharacters
@@ -81,6 +82,7 @@
using WTF::Base64DoNotInsertLFs;
using WTF::Base64InsertLFs;
using WTF::Base64DecodePolicy;
+using WTF::Base64FailOnInvalidCharacterOrExcessPadding;
using WTF::Base64FailOnInvalidCharacter;
using WTF::Base64IgnoreWhitespace;
using WTF::Base64IgnoreInvalidCharacters;
Modified: trunk/Source/WebCore/ChangeLog (153903 => 153904)
--- trunk/Source/WebCore/ChangeLog 2013-08-09 18:40:48 UTC (rev 153903)
+++ trunk/Source/WebCore/ChangeLog 2013-08-09 18:54:32 UTC (rev 153904)
@@ -1,5 +1,24 @@
2013-08-09 Christophe Dumez <[email protected]>
+ Make atob() throw an InvalidCharacterError on excess padding characters
+ https://bugs.webkit.org/show_bug.cgi?id=118898
+
+ Reviewed by Darin Adler.
+
+ According to the latest specification, window.atob() should throw an
+ InvalidCharacterError on excess padding characters:
+ http://www.whatwg.org/specs/web-apps/current-work/multipage/webappapis.html#dom-windowbase64-atob
+
+ This behavior is consistent with both Firefox, IE10 and recently Blink.
+
+ No new tests, already covered by:
+ fast/dom/Window/atob-btoa.html
+
+ * page/DOMWindow.cpp:
+ (WebCore::DOMWindow::atob):
+
+2013-08-09 Christophe Dumez <[email protected]>
+
Make DOMImplementation::hasFeature() behave according to specification
https://bugs.webkit.org/show_bug.cgi?id=119329
Modified: trunk/Source/WebCore/page/DOMWindow.cpp (153903 => 153904)
--- trunk/Source/WebCore/page/DOMWindow.cpp 2013-08-09 18:40:48 UTC (rev 153903)
+++ trunk/Source/WebCore/page/DOMWindow.cpp 2013-08-09 18:54:32 UTC (rev 153904)
@@ -1123,7 +1123,7 @@
}
Vector<char> out;
- if (!base64Decode(encodedString, out, Base64FailOnInvalidCharacter)) {
+ if (!base64Decode(encodedString, out, Base64FailOnInvalidCharacterOrExcessPadding)) {
ec = INVALID_CHARACTER_ERR;
return String();
}