summaryrefslogtreecommitdiffstats
path: root/dom
diff options
context:
space:
mode:
Diffstat (limited to 'dom')
-rw-r--r--dom/base/FileReader.cpp4
-rw-r--r--dom/base/nsContentUtils.cpp10
-rw-r--r--dom/base/nsContentUtils.h10
3 files changed, 19 insertions, 5 deletions
diff --git a/dom/base/FileReader.cpp b/dom/base/FileReader.cpp
index 003edc61f..63a0ef2ee 100644
--- a/dom/base/FileReader.cpp
+++ b/dom/base/FileReader.cpp
@@ -452,8 +452,8 @@ FileReader::GetAsText(Blob *aBlob,
}
}
- nsDependentCSubstring data(aFileData, aDataLen);
- return nsContentUtils::ConvertStringFromEncoding(encoding, data, aResult);
+ return nsContentUtils::ConvertStringFromEncoding(
+ encoding, aFileData, aDataLen, aResult);
}
nsresult
diff --git a/dom/base/nsContentUtils.cpp b/dom/base/nsContentUtils.cpp
index 29d28f8ce..1cc352685 100644
--- a/dom/base/nsContentUtils.cpp
+++ b/dom/base/nsContentUtils.cpp
@@ -4128,9 +4128,15 @@ nsContentUtils::GetSubdocumentWithOuterWindowId(nsIDocument *aDocument,
/* static */
nsresult
nsContentUtils::ConvertStringFromEncoding(const nsACString& aEncoding,
- const nsACString& aInput,
+ const char* aInput,
+ uint32_t aInputLen,
nsAString& aOutput)
{
+ CheckedInt32 len = aInputLen;
+ if (!len.isValid()) {
+ return NS_ERROR_OUT_OF_MEMORY;
+ }
+
nsAutoCString encoding;
if (aEncoding.IsEmpty()) {
encoding.AssignLiteral("UTF-8");
@@ -4142,7 +4148,7 @@ nsContentUtils::ConvertStringFromEncoding(const nsACString& aEncoding,
nsAutoPtr<TextDecoder> decoder(new TextDecoder());
decoder->InitWithEncoding(encoding, false);
- decoder->Decode(aInput.BeginReading(), aInput.Length(), false,
+ decoder->Decode(aInput, len.value(), false,
aOutput, rv);
return rv.StealNSResult();
}
diff --git a/dom/base/nsContentUtils.h b/dom/base/nsContentUtils.h
index 278fbd008..f688eeecf 100644
--- a/dom/base/nsContentUtils.h
+++ b/dom/base/nsContentUtils.h
@@ -554,9 +554,17 @@ public:
* string (meaning UTF-8)
*/
static nsresult ConvertStringFromEncoding(const nsACString& aEncoding,
- const nsACString& aInput,
+ const char* aInput,
+ uint32_t aInputLen,
nsAString& aOutput);
+ static nsresult ConvertStringFromEncoding(const nsACString& aEncoding,
+ const nsACString& aInput,
+ nsAString& aOutput) {
+ return ConvertStringFromEncoding(
+ aEncoding, aInput.BeginReading(), aInput.Length(), aOutput);
+ }
+
/**
* Determine whether a buffer begins with a BOM for UTF-8, UTF-16LE,
* UTF-16BE