[SCM] WebKit Debian packaging branch, debian/experimental, updated. upstream/1.3.3-9427-gc2be6fc

commit-queue at webkit.org commit-queue at webkit.org
Wed Dec 22 14:09:15 UTC 2010


The following commit has been merged in the debian/experimental branch:
commit 1f7b1f71a5b061b8950fa3af290be56b7d99f7ea
Author: commit-queue at webkit.org <commit-queue at webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Date:   Tue Oct 5 05:06:00 2010 +0000

    2010-10-04  Patrick Gansterer  <paroga at paroga.com>
    
            Reviewed by Darin Adler.
    
            Add Base64DecodePolicy option at base64Decode()
            https://bugs.webkit.org/show_bug.cgi?id=41510
    
            * fast/dom/Window/atob-btoa-expected.txt:
            * fast/dom/Window/atob-btoa.html:
            * platform/mac/fast/loader/user-stylesheet-fast-path-expected.txt:
            * platform/mac/fast/loader/user-stylesheet-fast-path.html: Added additional data urls tests.
    2010-10-04  Patrick Gansterer  <paroga at paroga.com>
    
            Reviewed by Darin Adler.
    
            Add Base64DecodePolicy option at base64Decode()
            https://bugs.webkit.org/show_bug.cgi?id=41510
    
            Add an option for ignoring characters in base64 data.
            This is necessary for decoding data urls.
    
            Also add an overload to decode WebCore::String directly.
    
            * page/DOMWindow.cpp:
            (WebCore::DOMWindow::atob):
            * page/Page.cpp:
            (WebCore::Page::userStyleSheetLocationChanged):
            * platform/text/Base64.cpp:
            (WebCore::base64Encode):
            (WebCore::base64Decode):
            (WebCore::base64DecodeInternal):
            * platform/text/Base64.h:
            (WebCore::):
    
    git-svn-id: http://svn.webkit.org/repository/webkit/trunk@69072 268f45cc-cd09-0410-ab3c-d52691b4dbfc

diff --git a/LayoutTests/ChangeLog b/LayoutTests/ChangeLog
index 1a2d187..f9fb2e1 100644
--- a/LayoutTests/ChangeLog
+++ b/LayoutTests/ChangeLog
@@ -1,3 +1,15 @@
+2010-10-04  Patrick Gansterer  <paroga at paroga.com>
+
+        Reviewed by Darin Adler.
+
+        Add Base64DecodePolicy option at base64Decode()
+        https://bugs.webkit.org/show_bug.cgi?id=41510
+
+        * fast/dom/Window/atob-btoa-expected.txt:
+        * fast/dom/Window/atob-btoa.html:
+        * platform/mac/fast/loader/user-stylesheet-fast-path-expected.txt:
+        * platform/mac/fast/loader/user-stylesheet-fast-path.html: Added additional data urls tests.
+
 2010-10-04  Yael Aharon  <yael.aharon at nokia.com>
 
         Reviewed by Antonio Gomes.
diff --git a/LayoutTests/fast/dom/Window/atob-btoa-expected.txt b/LayoutTests/fast/dom/Window/atob-btoa-expected.txt
index cef76a7..232b118 100644
--- a/LayoutTests/fast/dom/Window/atob-btoa-expected.txt
+++ b/LayoutTests/fast/dom/Window/atob-btoa-expected.txt
@@ -35,8 +35,13 @@ PASS window.atob("тест") threw exception Error: INVALID_CHARACTER_ERR: DOM E
 PASS window.atob("z") threw exception Error: INVALID_CHARACTER_ERR: DOM Exception 5.
 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("zzzz") is "Ï<ó"
 PASS window.atob("zzzzz") threw exception Error: INVALID_CHARACTER_ERR: DOM Exception 5.
+PASS window.atob("z=zz") threw exception Error: INVALID_CHARACTER_ERR: DOM Exception 5.
 PASS window.atob("=") threw exception Error: INVALID_CHARACTER_ERR: DOM Exception 5.
 PASS window.atob("==") threw exception Error: INVALID_CHARACTER_ERR: DOM Exception 5.
 PASS window.atob("===") threw exception Error: INVALID_CHARACTER_ERR: DOM Exception 5.
diff --git a/LayoutTests/fast/dom/Window/atob-btoa.html b/LayoutTests/fast/dom/Window/atob-btoa.html
index f6abb98..c250c97 100644
--- a/LayoutTests/fast/dom/Window/atob-btoa.html
+++ b/LayoutTests/fast/dom/Window/atob-btoa.html
@@ -48,8 +48,13 @@ shouldThrow('window.atob("тест")');
 shouldThrow('window.atob("z")');
 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"');
 shouldBe('window.atob("zzzz")', '"Ï\u003Có"');
 shouldThrow('window.atob("zzzzz")');
+shouldThrow('window.atob("z=zz")');
 shouldThrow('window.atob("=")');
 shouldThrow('window.atob("==")');
 shouldThrow('window.atob("===")');
diff --git a/LayoutTests/platform/mac/fast/loader/user-stylesheet-fast-path-expected.txt b/LayoutTests/platform/mac/fast/loader/user-stylesheet-fast-path-expected.txt
index cb45d38..ffd57c3 100644
--- a/LayoutTests/platform/mac/fast/loader/user-stylesheet-fast-path-expected.txt
+++ b/LayoutTests/platform/mac/fast/loader/user-stylesheet-fast-path-expected.txt
@@ -1,6 +1,9 @@
 This tests that when the user style sheet location is set to a data: URL with base64-encoded UTF-8 data, the style sheet is processed synchronously, instead of invoking the asynchronous loader.
 
 PASS 100px
+PASS 110px
+PASS 120px
+PASS 130px
 PASS 140px
 PASS 150px
 PASS 160px
diff --git a/LayoutTests/platform/mac/fast/loader/user-stylesheet-fast-path.html b/LayoutTests/platform/mac/fast/loader/user-stylesheet-fast-path.html
index a920bfe..3584421 100644
--- a/LayoutTests/platform/mac/fast/loader/user-stylesheet-fast-path.html
+++ b/LayoutTests/platform/mac/fast/loader/user-stylesheet-fast-path.html
@@ -6,6 +6,9 @@
 <script>
     var testObjects = [
         {result:true,  size:"100px", url:"data:text/css;charset=utf-8;base64,Ym9keSB7Zm9udC1zaXplOiAxMDBweH0="},
+        {result:true,  size:"110px", url:encodeURI("data:text/css;charset=utf-8;base64,                       Ym9keSB7Zm9udC1zaXplOiAxMTBweH0=                  ")},
+        {result:true,  size:"120px", url:encodeURI("data:text/css;charset=utf-8;base64,\n \r \t Ym9k \t eSB7 \r Zm9ud \n \n C1zaXp \r lOiAxM \t jBweH0= \t \r \n")},
+        {result:true,  size:"130px", url:encodeURI("data:text/css;charset=utf-8;base64,\u0059 \u006D \u0039 \u006B eSB7Zm9ud C1zaXplOiAxMzBwe \u0048 \u0030 \u003D")},
         {result:false, size:"140px", url:"data:text/css;charset=utf-8;base64,Ym9k$#eSB7Zm#9ud(C1zaXp)lOiAxNDBweH0="},
         {result:false, size:"150px", url:"data:text/css;charset=utf-8;base64,Ym9ke%00SB7Z%20m9udC1z\n\taXplO#iAx%03NTBw%eH0="},
         {result:false, size:"160px", url:"%50%30%10%00%20%40"}
diff --git a/WebCore/ChangeLog b/WebCore/ChangeLog
index 6e1699e..381e5be 100644
--- a/WebCore/ChangeLog
+++ b/WebCore/ChangeLog
@@ -1,3 +1,26 @@
+2010-10-04  Patrick Gansterer  <paroga at paroga.com>
+
+        Reviewed by Darin Adler.
+
+        Add Base64DecodePolicy option at base64Decode()
+        https://bugs.webkit.org/show_bug.cgi?id=41510
+
+        Add an option for ignoring characters in base64 data.
+        This is necessary for decoding data urls.
+
+        Also add an overload to decode WebCore::String directly.
+
+        * page/DOMWindow.cpp:
+        (WebCore::DOMWindow::atob):
+        * page/Page.cpp:
+        (WebCore::Page::userStyleSheetLocationChanged):
+        * platform/text/Base64.cpp:
+        (WebCore::base64Encode):
+        (WebCore::base64Decode):
+        (WebCore::base64DecodeInternal):
+        * platform/text/Base64.h:
+        (WebCore::):
+
 2010-10-04  Ryuan Choi  <bunhere at gmail.com>
 
         Unreviewed build fix.
diff --git a/WebCore/page/DOMWindow.cpp b/WebCore/page/DOMWindow.cpp
index 343ca2c..5e8a57f 100644
--- a/WebCore/page/DOMWindow.cpp
+++ b/WebCore/page/DOMWindow.cpp
@@ -993,11 +993,8 @@ String DOMWindow::atob(const String& encodedString, ExceptionCode& ec)
         return String();
     }
 
-    Vector<char> in;
-    in.append(encodedString.characters(), encodedString.length());
     Vector<char> out;
-
-    if (!base64Decode(in, out)) {
+    if (!base64Decode(encodedString, out, FailOnInvalidCharacter)) {
         ec = INVALID_CHARACTER_ERR;
         return String();
     }
diff --git a/WebCore/page/Page.cpp b/WebCore/page/Page.cpp
index 12ca88c..fb0a9c9 100644
--- a/WebCore/page/Page.cpp
+++ b/WebCore/page/Page.cpp
@@ -635,22 +635,17 @@ void Page::userStyleSheetLocationChanged()
     m_didLoadUserStyleSheet = false;
     m_userStyleSheet = String();
     m_userStyleSheetModificationTime = 0;
-    
+
     // Data URLs with base64-encoded UTF-8 style sheets are common. We can process them
     // synchronously and avoid using a loader. 
     if (url.protocolIs("data") && url.string().startsWith("data:text/css;charset=utf-8;base64,")) {
         m_didLoadUserStyleSheet = true;
-        
-        const unsigned prefixLength = 35;
-        Vector<char> encodedData(url.string().length() - prefixLength);
-        for (unsigned i = prefixLength; i < url.string().length(); ++i)
-            encodedData[i - prefixLength] = static_cast<char>(url.string()[i]);
 
         Vector<char> styleSheetAsUTF8;
-        if (base64Decode(encodedData, styleSheetAsUTF8))
+        if (base64Decode(decodeURLEscapeSequences(url.string().substring(35)), styleSheetAsUTF8, IgnoreWhitespace))
             m_userStyleSheet = String::fromUTF8(styleSheetAsUTF8.data(), styleSheetAsUTF8.size());
     }
-    
+
     for (Frame* frame = mainFrame(); frame; frame = frame->tree()->traverseNext()) {
         if (frame->document())
             frame->document()->updatePageUserSheet();
diff --git a/WebCore/platform/text/Base64.cpp b/WebCore/platform/text/Base64.cpp
index cc22cf8..98b537a 100644
--- a/WebCore/platform/text/Base64.cpp
+++ b/WebCore/platform/text/Base64.cpp
@@ -2,6 +2,7 @@
    Copyright (C) 2000-2001 Dawit Alemayehu <adawit at kde.org>
    Copyright (C) 2006 Alexey Proskuryakov <ap at webkit.org>
    Copyright (C) 2007, 2008 Apple Inc. All rights reserved.
+   Copyright (C) 2010 Patrick Gansterer <paroga at paroga.com>
 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU Lesser General Public License (LGPL)
@@ -25,6 +26,7 @@
 
 #include <limits.h>
 #include <wtf/StringExtras.h>
+#include <wtf/text/WTFString.h>
 
 namespace WebCore {
 
@@ -70,7 +72,7 @@ void base64Encode(const char* data, unsigned len, Vector<char>& out, bool insert
         return;
 
     // If the input string is pathologically large, just return nothing.
-    // Note: Keep this in sync with the "out_len" computation below.
+    // Note: Keep this in sync with the "outLength" computation below.
     // Rather than being perfectly precise, this is a bit conservative.
     const unsigned maxInputBufferSize = UINT_MAX / 77 * 76 / 4 * 3 - 2;
     if (len > maxInputBufferSize)
@@ -79,21 +81,21 @@ void base64Encode(const char* data, unsigned len, Vector<char>& out, bool insert
     unsigned sidx = 0;
     unsigned didx = 0;
 
-    unsigned out_len = ((len + 2) / 3) * 4;
+    unsigned outLength = ((len + 2) / 3) * 4;
 
     // Deal with the 76 character per line limit specified in RFC 2045.
-    insertLFs = (insertLFs && out_len > 76);
+    insertLFs = (insertLFs && outLength > 76);
     if (insertLFs)
-        out_len += ((out_len - 1) / 76);
+        outLength += ((outLength - 1) / 76);
 
     int count = 0;
-    out.grow(out_len);
+    out.grow(outLength);
 
     // 3-byte to 4-byte conversion + 0-63 to ascii printable conversion
     if (len > 1) {
         while (sidx < len - 2) {
             if (insertLFs) {
-                if (count && (count % 76) == 0)
+                if (count && !(count % 76))
                     out[didx++] = '\n';
                 count += 4;
             }
@@ -106,7 +108,7 @@ void base64Encode(const char* data, unsigned len, Vector<char>& out, bool insert
     }
 
     if (sidx < len) {
-        if (insertLFs && (count > 0) && (count % 76) == 0)
+        if (insertLFs && (count > 0) && !(count % 76))
            out[didx++] = '\n';
 
         out[didx++] = base64EncMap[(data[sidx] >> 2) & 077];
@@ -124,7 +126,7 @@ void base64Encode(const char* data, unsigned len, Vector<char>& out, bool insert
     }
 }
 
-bool base64Decode(const Vector<char>& in, Vector<char>& out)
+bool base64Decode(const Vector<char>& in, Vector<char>& out, Base64DecodePolicy policy)
 {
     out.clear();
 
@@ -132,36 +134,49 @@ bool base64Decode(const Vector<char>& in, Vector<char>& out)
     if (in.size() > UINT_MAX)
         return false;
 
-    return base64Decode(in.data(), in.size(), out);
+    return base64Decode(in.data(), in.size(), out, policy);
 }
 
-bool base64Decode(const char* data, unsigned len, Vector<char>& out)
+template<typename T>
+static inline bool base64DecodeInternal(const T* data, unsigned len, Vector<char>& out, Base64DecodePolicy policy)
 {
     out.clear();
-    if (len == 0)
+    if (!len)
         return true;
 
-    while (len && data[len-1] == '=')
-        --len;
-
     out.grow(len);
+
+    bool sawEqualsSign = false;
+    unsigned outLength = 0;
     for (unsigned idx = 0; idx < len; idx++) {
-        unsigned char ch = data[idx];
-        if ((ch > 47 && ch < 58) || (ch > 64 && ch < 91) || (ch > 96 && ch < 123) || ch == '+' || ch == '/' || ch == '=')
-            out[idx] = base64DecMap[ch];
-        else
+        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)
+                return false;
+            out[outLength] = base64DecMap[ch];
+            outLength++;
+        } else if (policy == FailOnInvalidCharacter || (policy == IgnoreWhitespace && !isSpaceOrNewline(ch)))
             return false;
     }
 
+    if (!outLength)
+        return !sawEqualsSign;
+
+    // Valid data is (n * 4 + [0,2,3]) characters long.
+    if ((outLength % 4) == 1)
+        return false;
+    
     // 4-byte to 3-byte conversion
-    unsigned outLen = len - ((len + 3) / 4);
-    if (!outLen || ((outLen + 2) / 3) * 4 < len)
+    outLength -= (outLength + 3) / 4;
+    if (!outLength)
         return false;
 
     unsigned sidx = 0;
     unsigned didx = 0;
-    if (outLen > 1) {
-        while (didx < outLen - 2) {
+    if (outLength > 1) {
+        while (didx < outLength - 2) {
             out[didx] = (((out[sidx] << 2) & 255) | ((out[sidx + 1] >> 4) & 003));
             out[didx + 1] = (((out[sidx + 1] << 4) & 255) | ((out[sidx + 2] >> 2) & 017));
             out[didx + 2] = (((out[sidx + 2] << 6) & 255) | (out[sidx + 3] & 077));
@@ -170,16 +185,26 @@ bool base64Decode(const char* data, unsigned len, Vector<char>& out)
         }
     }
 
-    if (didx < outLen)
+    if (didx < outLength)
         out[didx] = (((out[sidx] << 2) & 255) | ((out[sidx + 1] >> 4) & 003));
 
-    if (++didx < outLen)
+    if (++didx < outLength)
         out[didx] = (((out[sidx + 1] << 4) & 255) | ((out[sidx + 2] >> 2) & 017));
 
-    if (outLen < out.size())
-        out.shrink(outLen);
+    if (outLength < out.size())
+        out.shrink(outLength);
 
     return true;
 }
 
+bool base64Decode(const char* data, unsigned len, Vector<char>& out, Base64DecodePolicy policy)
+{
+    return base64DecodeInternal<char>(data, len, out, policy);
 }
+
+bool base64Decode(const String& in, Vector<char>& out, Base64DecodePolicy policy)
+{
+    return base64DecodeInternal<UChar>(in.characters(), in.length(), out, policy);
+}
+
+} // namespace WebCore
diff --git a/WebCore/platform/text/Base64.h b/WebCore/platform/text/Base64.h
index 53b29b0..211bd3c 100644
--- a/WebCore/platform/text/Base64.h
+++ b/WebCore/platform/text/Base64.h
@@ -1,5 +1,6 @@
 /*
- * Copyright (C) 2006 Alexey Proskuryakov (ap at webkit.org)
+ * Copyright (C) 2006 Alexey Proskuryakov <ap at webkit.org>
+ * Copyright (C) 2010 Patrick Gansterer <paroga at paroga.com>
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -26,16 +27,19 @@
 #ifndef Base64_h
 #define Base64_h
 
+#include <wtf/Forward.h>
 #include <wtf/Vector.h>
 
 namespace WebCore {
 
+enum Base64DecodePolicy { FailOnInvalidCharacter, IgnoreWhitespace, IgnoreInvalidCharacters };
+
 void base64Encode(const Vector<char>&, Vector<char>&, bool insertLFs = false);
 void base64Encode(const char*, unsigned, Vector<char>&, bool insertLFs = false);
 
-// this decoder is not general purpose - it returns an error if it encounters a linefeed, as needed for window.atob
-bool base64Decode(const Vector<char>&, Vector<char>&);
-bool base64Decode(const char*, unsigned, Vector<char>&);
+bool base64Decode(const String&, Vector<char>&, Base64DecodePolicy = FailOnInvalidCharacter);
+bool base64Decode(const Vector<char>&, Vector<char>&, Base64DecodePolicy = FailOnInvalidCharacter);
+bool base64Decode(const char*, unsigned, Vector<char>&, Base64DecodePolicy = FailOnInvalidCharacter);
 
 }
 

-- 
WebKit Debian packaging



More information about the Pkg-webkit-commits mailing list