Reviewed by Darin.
authorap <ap@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 28 Jan 2006 08:53:52 +0000 (08:53 +0000)
committerap <ap@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 28 Jan 2006 08:53:52 +0000 (08:53 +0000)
        - fix http://bugzilla.opendarwin.org/show_bug.cgi?id=5163
        RealPlayer.GetTitle() Crashes Safari/Dashboard

        * bindings/c/c_utility.cpp: (KJS::Bindings::convertUTF8ToUTF16):
        Fallback to kCFStringEncodingWindowsLatin1 if the passed buffer is not valid UTF-8, preventing crashes.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@12426 268f45cc-cd09-0410-ab3c-d52691b4dbfc

JavaScriptCore/ChangeLog
JavaScriptCore/bindings/c/c_utility.cpp

index ed3d58ff2e22ba397c4cdf120b66c04adcb83417..f5b1741a2db1cb1bce18f014624bcfe14e4206ee 100644 (file)
@@ -1,3 +1,13 @@
+2006-01-28  Alexey Proskuryakov  <ap@nypop.com>
+
+        Reviewed by Darin.
+
+        - fix http://bugzilla.opendarwin.org/show_bug.cgi?id=5163
+        RealPlayer.GetTitle() Crashes Safari/Dashboard
+
+        * bindings/c/c_utility.cpp: (KJS::Bindings::convertUTF8ToUTF16):
+        Fallback to kCFStringEncodingWindowsLatin1 if the passed buffer is not valid UTF-8, preventing crashes.
+
 2006-01-25  George Staikos <staikos@opensource.apple.com>
 
        Reviewed by Darin.
index e168f7ff5ebff91172c9e72aa46766db11fedc25..f20dae4d7e6763c6efb7369dddcca016fee922dd 100644 (file)
@@ -1,5 +1,6 @@
 /*
  * Copyright (C) 2004 Apple Computer, Inc.  All rights reserved.
+ * Copyright (C) 2006 Alexey Proskuryakov (ap@nypop.com)
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -48,6 +49,12 @@ void convertUTF8ToUTF16(const NPUTF8 *UTF8Chars, int UTF8Length, NPUTF16 **UTF16
         UTF8Length = strlen(UTF8Chars);
 
     CFStringRef stringRef = CFStringCreateWithBytes(NULL, (const UInt8*)UTF8Chars, (CFIndex)UTF8Length, kCFStringEncodingUTF8, false);
+    
+    // Some plugins return invalid UTF-8 in NPVariantType_String, see <http://bugzilla.opendarwin.org/show_bug.cgi?id=5163>
+    if (!stringRef)
+        stringRef = CFStringCreateWithBytes(NULL, (const UInt8*)UTF8Chars, (CFIndex)UTF8Length, kCFStringEncodingWindowsLatin1, false);
+
+    assert(stringRef); // there is no "bad data" for kCFStringEncodingWindowsLatin1
 
     *UTF16Length = (unsigned int)CFStringGetLength(stringRef);
     *UTF16Chars = (NPUTF16 *)malloc(sizeof(NPUTF16) * (*UTF16Length));