Backed out changeset 4bac27faa19b (bug 1070763) for crashes and broken websites. r=backout a=backout
authorSebastian Hengst <archaeopteryx@coole-files.de>
Sat, 14 Oct 2017 23:50:33 +0200
changeset 386241 f3da88fdee4ab79a2212f8d2d1efd37fb5009b58
parent 386240 32fdad6bf6f0417d9b094a13e0670ddb76a085b8
child 386268 ec0d413df945b26b2470e9b32423cdf9b1f84e29
push id32682
push userarchaeopteryx@coole-files.de
push dateSat, 14 Oct 2017 21:51:14 +0000
treeherdermozilla-central@f3da88fdee4a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbackout, backout
bugs1070763
milestone58.0a1
backs out4bac27faa19b0ff556aff9a466053239c1c05c8d
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Backed out changeset 4bac27faa19b (bug 1070763) for crashes and broken websites. r=backout a=backout MozReview-Commit-ID: 6BAkoAT8JyJ
dom/xhr/XMLHttpRequestMainThread.cpp
dom/xhr/XMLHttpRequestMainThread.h
testing/web-platform/meta/XMLHttpRequest/responsetext-decoding.htm.ini
testing/web-platform/meta/XMLHttpRequest/send-receive-utf16.htm.ini
testing/web-platform/meta/encoding/unsupported-encodings.html.ini
--- a/dom/xhr/XMLHttpRequestMainThread.cpp
+++ b/dom/xhr/XMLHttpRequestMainThread.cpp
@@ -516,35 +516,25 @@ XMLHttpRequestMainThread::DetectCharset(
   if (mResponseType == XMLHttpRequestResponseType::Json &&
       encoding != UTF_8_ENCODING) {
     // The XHR spec says only UTF-8 is supported for responseType == "json"
     LogMessage("JSONCharsetWarning", GetOwner());
     encoding = UTF_8_ENCODING;
   }
 
   mResponseCharset = encoding;
-
-  // Only sniff the BOM for non-JSON responseTypes
-  if (mResponseType == XMLHttpRequestResponseType::Json) {
-    mDecoder = encoding->NewDecoderWithBOMRemoval();
-  } else {
-    mDecoder = encoding->NewDecoder();
-  }
+  mDecoder = encoding->NewDecoderWithBOMRemoval();
 
   return NS_OK;
 }
 
 nsresult
 XMLHttpRequestMainThread::AppendToResponseText(const char * aSrcBuffer,
-                                               uint32_t aSrcBufferLen,
-                                               bool aLast)
+                                               uint32_t aSrcBufferLen)
 {
-  // Call this with an empty buffer to send the decoder the signal
-  // that we have hit the end of the stream.
-
   NS_ENSURE_STATE(mDecoder);
 
   CheckedInt<size_t> destBufferLen =
     mDecoder->MaxUTF16BufferLength(aSrcBufferLen);
   if (!destBufferLen.isValid()) {
     return NS_ERROR_OUT_OF_MEMORY;
   }
 
@@ -555,24 +545,25 @@ XMLHttpRequestMainThread::AppendToRespon
   }
 
   XMLHttpRequestStringWriterHelper helper(mResponseText);
 
   if (!helper.AddCapacity(destBufferLen.value())) {
     return NS_ERROR_OUT_OF_MEMORY;
   }
 
+  // XXX there's no handling for incomplete byte sequences on EOF!
   uint32_t result;
   size_t read;
   size_t written;
   bool hadErrors;
   Tie(result, read, written, hadErrors) = mDecoder->DecodeToUTF16(
     AsBytes(MakeSpan(aSrcBuffer, aSrcBufferLen)),
     MakeSpan(helper.EndOfExistingData(), destBufferLen.value()),
-    aLast);
+    false);
   MOZ_ASSERT(result == kInputEmpty);
   MOZ_ASSERT(read == aSrcBufferLen);
   MOZ_ASSERT(written <= destBufferLen.value());
   Unused << hadErrors;
   helper.AddLength(written);
   return NS_OK;
 }
 
@@ -2193,22 +2184,16 @@ XMLHttpRequestMainThread::OnStopRequest(
 {
   AUTO_PROFILER_LABEL("XMLHttpRequestMainThread::OnStopRequest", NETWORK);
 
   if (request != mChannel) {
     // Can this still happen?
     return NS_OK;
   }
 
-  // send the decoder the signal that we've hit the end of the stream,
-  // but only when parsing text (not XML, which does this already).
-  if (mDecoder && !mFlagParseBody) {
-    AppendToResponseText(nullptr, 0, true);
-  }
-
   mWaitingForOnStopRequest = false;
 
   if (mRequestObserver) {
     NS_ASSERTION(mFirstStartRequestSeen, "Inconsistent state!");
     mFirstStartRequestSeen = false;
     mRequestObserver->OnStopRequest(request, ctxt, status);
   }
 
@@ -2374,17 +2359,17 @@ XMLHttpRequestMainThread::OnBodyParseEnd
 
 void
 XMLHttpRequestMainThread::MatchCharsetAndDecoderToResponseDocument()
 {
   if (mResponseXML && mResponseCharset != mResponseXML->GetDocumentCharacterSet()) {
     mResponseCharset = mResponseXML->GetDocumentCharacterSet();
     TruncateResponseText();
     mResponseBodyDecodedPos = 0;
-    mDecoder = mResponseCharset->NewDecoder();
+    mDecoder = mResponseCharset->NewDecoderWithBOMRemoval();
   }
 }
 
 void
 XMLHttpRequestMainThread::ChangeStateToDone()
 {
   StopProgressEventTimer();
 
--- a/dom/xhr/XMLHttpRequestMainThread.h
+++ b/dom/xhr/XMLHttpRequestMainThread.h
@@ -515,18 +515,17 @@ protected:
     unsent,           // object has been constructed.
     opened,           // open() has been successfully invoked.
     headers_received, // redirects followed and response headers received.
     loading,          // response body is being received.
     done,             // data transfer concluded, whether success or error.
   };
 
   nsresult DetectCharset();
-  nsresult AppendToResponseText(const char* aBuffer, uint32_t aBufferLen,
-                                bool aLast = false);
+  nsresult AppendToResponseText(const char * aBuffer, uint32_t aBufferLen);
   static nsresult StreamReaderFunc(nsIInputStream* in,
                                    void* closure,
                                    const char* fromRawSegment,
                                    uint32_t toOffset,
                                    uint32_t count,
                                    uint32_t *writeCount);
   nsresult CreateResponseParsedJSON(JSContext* aCx);
   // Change the state of the object with this. The broadcast argument
new file mode 100644
--- /dev/null
+++ b/testing/web-platform/meta/XMLHttpRequest/responsetext-decoding.htm.ini
@@ -0,0 +1,11 @@
+[responsetext-decoding.htm]
+  type: testharness
+  [XMLHttpRequest: responseText decoding (text/plain %FE%FF)]
+    expected: FAIL
+
+  [XMLHttpRequest: responseText decoding (text/plain %FE%FF%FE%FF)]
+    expected: FAIL
+
+  [XMLHttpRequest: responseText decoding (text/plain %C2)]
+    expected: FAIL
+
new file mode 100644
--- /dev/null
+++ b/testing/web-platform/meta/XMLHttpRequest/send-receive-utf16.htm.ini
@@ -0,0 +1,5 @@
+[send-receive-utf16.htm]
+  type: testharness
+  [UTF-16 with BOM, no encoding in content-type]
+    expected: FAIL
+
--- a/testing/web-platform/meta/encoding/unsupported-encodings.html.ini
+++ b/testing/web-platform/meta/encoding/unsupported-encodings.html.ini
@@ -1,8 +1,20 @@
 [unsupported-encodings.html]
   type: testharness
+  [UTF-32 with BOM should decode as UTF-16LE]
+    expected: FAIL
+
+  [utf-32 with BOM should decode as UTF-16LE]
+    expected: FAIL
+
+  [UTF-32LE with BOM should decode as UTF-16LE]
+    expected: FAIL
+
+  [utf-32le with BOM should decode as UTF-16LE]
+    expected: FAIL
+
   [UTF-32be with BOM should decode as windows-1252]
     expected: FAIL
 
   [utf-32be with BOM should decode as windows-1252]
     expected: FAIL