-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
https://bugs.webkit.org/show_bug.cgi?id=159180 <rdar://problem/26015178> Reviewed by Brent Fulgham. LayoutTests/imported/w3c: * web-platform-tests/dom/nodes/Document-characterSet-normalization-expected.txt: Source/WebCore: Test: fast/encoding/charset-replacement.html Add support for "replacement" codec according to the spec: https://encoding.spec.whatwg.org/#replacement According to the spec, encoding labels {"csiso2022kr", "hz-gb-2312", "iso-2022-cn", "iso-2022-cn-ext", "iso-2022-kr"} are used to conduct certain attacks that abuse a mismatch between encodings supported on the server and the client. Therefore, they are grouped under the "replacement" codec, which does the following things to prevent those attacks. 1) Decode: terminates with a single U+FFFD. 2) Encode: treated as UTF-8. Furthermore, the "replacement" codec is a specification convenience to group those vulnerable encoding labels. Therefore, it should not be able to use directly. This change is based on the following Blink changes: https://codereview.chromium.org/265973003, and https://codereview.chromium.org/261013007. * CMakeLists.txt: * WebCore.xcodeproj/project.pbxproj: * platform/text/TextAllInOne.cpp: * platform/text/TextCodecReplacement.cpp: Added. (WebCore::TextCodecReplacement::create): (WebCore::TextCodecReplacement::TextCodecReplacement): (WebCore::TextCodecReplacement::registerEncodingNames): (WebCore::TextCodecReplacement::registerCodecs): (WebCore::TextCodecReplacement::decode): * platform/text/TextCodecReplacement.h: Added. * platform/text/TextEncoding.cpp: (WebCore::TextEncoding::TextEncoding): * platform/text/TextEncodingRegistry.cpp: (WebCore::isReplacementEncoding): (WebCore::extendTextCodecMaps): * platform/text/TextEncodingRegistry.h: LayoutTests: * fast/encoding/char-decoding-expected.txt: * fast/encoding/char-decoding.html: * fast/encoding/char-encoding-expected.txt: * fast/encoding/char-encoding.html: * fast/encoding/charset-replacement-expected.txt: Added. * fast/encoding/charset-replacement.html: Added. Canonical link: https://commits.webkit.org/177346@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@202599 268f45cc-cd09-0410-ab3c-d52691b4dbfc
- Loading branch information
Jiewen Tan
committed
Jun 29, 2016
1 parent
f728182
commit 6934ec0
Showing
18 changed files
with
286 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
ALERT: ISO-8859-1 | ||
Test PASSED if the encoding of this document is the default encoding. | ||
Test FAILED if you see a U+FFFD character in a dumped render tree. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset=rEpLaCeMeNt> | ||
<script> | ||
if (window.testRunner) | ||
testRunner.dumpAsText(); | ||
alert(document.characterSet); | ||
</script> | ||
</head> | ||
<body> | ||
Test PASSED if the encoding of this document is the default encoding.<br> | ||
Test FAILED if you see a U+FFFD character in a dumped render tree.<br> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
/* | ||
* Copyright (C) 2016 Apple Inc. All rights reserved. | ||
* | ||
* Redistribution and use in source and binary forms, with or without | ||
* modification, are permitted provided that the following conditions | ||
* are met: | ||
* 1. Redistributions of source code must retain the above copyright | ||
* notice, this list of conditions and the following disclaimer. | ||
* 2. Redistributions in binary form must reproduce the above copyright | ||
* notice, this list of conditions and the following disclaimer in the | ||
* documentation and/or other materials provided with the distribution. | ||
* | ||
* THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' | ||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, | ||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS | ||
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF | ||
* THE POSSIBILITY OF SUCH DAMAGE. | ||
*/ | ||
|
||
#include "config.h" | ||
#include "TextCodecReplacement.h" | ||
|
||
namespace WebCore { | ||
|
||
static const UChar ReplacementCharacter[1] = { 0xFFFD }; | ||
|
||
std::unique_ptr<TextCodec> TextCodecReplacement::create(const TextEncoding&, const void*) | ||
{ | ||
return std::make_unique<TextCodecReplacement>(); | ||
} | ||
|
||
TextCodecReplacement::TextCodecReplacement() | ||
{ | ||
} | ||
|
||
void TextCodecReplacement::registerEncodingNames(EncodingNameRegistrar registrar) | ||
{ | ||
// The 'replacement' itself is not a valid label. It is the name of | ||
// a group of legacy encoding labels. Hence, it cannot be used directly. | ||
registrar("replacement", "replacement"); | ||
|
||
// The labels | ||
registrar("csiso2022kr", "replacement"); | ||
registrar("hz-gb-2312", "replacement"); | ||
registrar("iso-2022-cn", "replacement"); | ||
registrar("iso-2022-cn-ext", "replacement"); | ||
registrar("iso-2022-kr", "replacement"); | ||
} | ||
|
||
void TextCodecReplacement::registerCodecs(TextCodecRegistrar registrar) | ||
{ | ||
registrar("replacement", create, 0); | ||
} | ||
|
||
String TextCodecReplacement::decode(const char*, size_t, bool, bool, bool& sawError) | ||
{ | ||
sawError = true; | ||
if (m_sentEOF) | ||
return emptyString(); | ||
|
||
m_sentEOF = true; | ||
return ReplacementCharacter; | ||
} | ||
|
||
} // namespace WebCore |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* | ||
* Copyright (C) 2016 Apple Inc. All rights reserved. | ||
* | ||
* Redistribution and use in source and binary forms, with or without | ||
* modification, are permitted provided that the following conditions | ||
* are met: | ||
* 1. Redistributions of source code must retain the above copyright | ||
* notice, this list of conditions and the following disclaimer. | ||
* 2. Redistributions in binary form must reproduce the above copyright | ||
* notice, this list of conditions and the following disclaimer in the | ||
* documentation and/or other materials provided with the distribution. | ||
* | ||
* THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' | ||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, | ||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS | ||
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF | ||
* THE POSSIBILITY OF SUCH DAMAGE. | ||
*/ | ||
|
||
#ifndef TextCodecReplacement_h | ||
#define TextCodecReplacement_h | ||
|
||
#include "TextCodecUTF8.h" | ||
|
||
namespace WebCore { | ||
|
||
class TextCodecReplacement : public TextCodecUTF8 { | ||
public: | ||
static std::unique_ptr<TextCodec> create(const TextEncoding&, const void*); | ||
|
||
TextCodecReplacement(); | ||
|
||
static void registerEncodingNames(EncodingNameRegistrar); | ||
static void registerCodecs(TextCodecRegistrar); | ||
|
||
private: | ||
String decode(const char*, size_t length, bool flush, bool stopOnError, bool& sawError) override; | ||
|
||
bool m_sentEOF { false }; | ||
|
||
}; | ||
|
||
} // namespace WebCore | ||
|
||
#endif /* TextCodecReplacement_h */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.