Backed out changeset 4bac27faa19b (bug 1070763) for crashes and broken websites. r=backout a=backout

MozReview-Commit-ID: 6BAkoAT8JyJ
This commit is contained in:
Sebastian Hengst 2017-10-14 23:50:33 +02:00
parent 776dca65f3
commit 24f9efc1d1
5 changed files with 34 additions and 22 deletions

View File

@ -521,25 +521,15 @@ XMLHttpRequestMainThread::DetectCharset()
}
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 =
@ -560,6 +550,7 @@ XMLHttpRequestMainThread::AppendToResponseText(const char * aSrcBuffer,
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;
@ -567,7 +558,7 @@ XMLHttpRequestMainThread::AppendToResponseText(const char * aSrcBuffer,
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());
@ -2198,12 +2189,6 @@ XMLHttpRequestMainThread::OnStopRequest(nsIRequest *request, nsISupports *ctxt,
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) {
@ -2379,7 +2364,7 @@ XMLHttpRequestMainThread::MatchCharsetAndDecoderToResponseDocument()
mResponseCharset = mResponseXML->GetDocumentCharacterSet();
TruncateResponseText();
mResponseBodyDecodedPos = 0;
mDecoder = mResponseCharset->NewDecoder();
mDecoder = mResponseCharset->NewDecoderWithBOMRemoval();
}
}

View File

@ -520,8 +520,7 @@ protected:
};
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,

View File

@ -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

View File

@ -0,0 +1,5 @@
[send-receive-utf16.htm]
type: testharness
[UTF-16 with BOM, no encoding in content-type]
expected: FAIL

View File

@ -1,5 +1,17 @@
[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