summaryrefslogtreecommitdiffstats
path: root/WebCore/platform/text/TextCodecUTF16.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'WebCore/platform/text/TextCodecUTF16.cpp')
-rw-r--r--WebCore/platform/text/TextCodecUTF16.cpp12
1 files changed, 9 insertions, 3 deletions
diff --git a/WebCore/platform/text/TextCodecUTF16.cpp b/WebCore/platform/text/TextCodecUTF16.cpp
index 5c23732..95f4dc4 100644
--- a/WebCore/platform/text/TextCodecUTF16.cpp
+++ b/WebCore/platform/text/TextCodecUTF16.cpp
@@ -31,6 +31,8 @@
#include <wtf/text/StringBuffer.h>
#include <wtf/PassOwnPtr.h>
+using namespace std;
+
namespace WebCore {
void TextCodecUTF16::registerEncodingNames(EncodingNameRegistrar registrar)
@@ -115,23 +117,27 @@ String TextCodecUTF16::decode(const char* bytes, size_t length, bool, bool, bool
CString TextCodecUTF16::encode(const UChar* characters, size_t length, UnencodableHandling)
{
+ if (length > numeric_limits<size_t>::max() / 2)
+ CRASH();
+
char* bytes;
CString string = CString::newUninitialized(length * 2, bytes);
// FIXME: CString is not a reasonable data structure for encoded UTF-16, which will have
- // null characters inside it. Perhaps the result of encode should not be a CString?
- if (m_littleEndian)
+ // null characters inside it. Perhaps the result of encode should not be a CString.
+ if (m_littleEndian) {
for (size_t i = 0; i < length; ++i) {
UChar c = characters[i];
bytes[i * 2] = c;
bytes[i * 2 + 1] = c >> 8;
}
- else
+ } else {
for (size_t i = 0; i < length; ++i) {
UChar c = characters[i];
bytes[i * 2] = c >> 8;
bytes[i * 2 + 1] = c;
}
+ }
return string;
}