Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(434)

Unified Diff: third_party/WebKit/Source/core/html/parser/TextResourceDecoder.cpp

Issue 2212393003: Fix BOM handling in TextResourceDecoder on partial data (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: +comment Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/core/html/parser/TextResourceDecoder.cpp
diff --git a/third_party/WebKit/Source/core/html/parser/TextResourceDecoder.cpp b/third_party/WebKit/Source/core/html/parser/TextResourceDecoder.cpp
index 1185bd8cb73e6b29e28c1a89899e86a5abaea7b5..6c97585b46d66485714cb03b9010c6ab26300ead 100644
--- a/third_party/WebKit/Source/core/html/parser/TextResourceDecoder.cpp
+++ b/third_party/WebKit/Source/core/html/parser/TextResourceDecoder.cpp
@@ -214,7 +214,7 @@ size_t TextResourceDecoder::checkForBOM(const char* data, size_t len)
setEncoding(UTF8Encoding(), AutoDetectedEncoding);
lengthOfBOM = 3;
} else if (m_encodingDetectionOption != AlwaysUseUTF8ForText) {
- if (c1 == 0xFF && c2 == 0xFE) {
+ if (c1 == 0xFF && c2 == 0xFE && bufferLength + len >= 4) {
if (c3 || c4) {
setEncoding(UTF16LittleEndianEncoding(), AutoDetectedEncoding);
lengthOfBOM = 2;
@@ -369,9 +369,18 @@ bool TextResourceDecoder::shouldAutoDetect() const
String TextResourceDecoder::decode(const char* data, size_t len)
{
size_t lengthOfBOM = 0;
- if (!m_checkedForBOM)
+ if (!m_checkedForBOM) {
lengthOfBOM = checkForBOM(data, len);
+ // BOM check can fail when the available data is not enough.
+ if (!m_checkedForBOM) {
+ DCHECK_EQ(0u, lengthOfBOM);
+ m_buffer.append(data, len);
+ return emptyString();
+ }
+ }
+ DCHECK_LE(lengthOfBOM, m_buffer.size() + len);
+
bool movedDataToBuffer = false;
if (m_contentType == CSSContent && !m_checkedForCSSCharset) {
« no previous file with comments | « third_party/WebKit/Source/core/core.gypi ('k') | third_party/WebKit/Source/core/html/parser/TextResourceDecoderTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698