Bug 673301, crash using non-string data with text/plain drags, r=josh
☠☠ backed out by 5e542afdd814 ☠ ☠
authorNeil Deakin <neil@mozilla.com>
Fri, 05 Aug 2011 15:24:24 -0400
changeset 73922 3985e7570ab65a24576bb8ead0286d5c810b0167
parent 73921 7fece42cb99a9c3637b0926e43aac9156dfe1976
child 73923 43615caacb4894fd3009956cc9730a261c7e0af8
push id2
push userbsmedberg@mozilla.com
push dateFri, 19 Aug 2011 14:38:13 +0000
reviewersjosh
bugs673301
milestone8.0a1
Bug 673301, crash using non-string data with text/plain drags, r=josh
widget/src/cocoa/nsClipboard.mm
widget/tests/Makefile.in
widget/tests/test_bug673301.xul
--- a/widget/src/cocoa/nsClipboard.mm
+++ b/widget/src/cocoa/nsClipboard.mm
@@ -423,16 +423,18 @@ nsClipboard::PasteboardDictFromTransfera
     NSString *pboardType = nil;
 
     if (nsClipboard::IsStringType(flavorStr, &pboardType)) {
       void* data = nsnull;
       PRUint32 dataSize = 0;
       nsCOMPtr<nsISupports> genericDataWrapper;
       rv = aTransferable->GetTransferData(flavorStr, getter_AddRefs(genericDataWrapper), &dataSize);
       nsPrimitiveHelpers::CreateDataFromPrimitive(flavorStr, genericDataWrapper, &data, dataSize);
+      if (!data)
+        continue;
       
       NSString* nativeString = [NSString stringWithCharacters:(const unichar*)data length:(dataSize / sizeof(PRUnichar))];
       // be nice to Carbon apps, normalize the receiver's contents using Form C.
       nativeString = [nativeString precomposedStringWithCanonicalMapping];
 
       [pasteboardOutputDict setObject:nativeString forKey:pboardType];
       
       nsMemory::Free(data);
--- a/widget/tests/Makefile.in
+++ b/widget/tests/Makefile.in
@@ -105,16 +105,17 @@ ifeq ($(MOZ_WIDGET_TOOLKIT),cocoa)
                test_platform_colors.xul \
                test_standalone_native_menu.xul \
                standalone_native_menu_window.xul \
                test_bug586713.xul \
                bug586713_window.xul \
                test_key_event_counts.xul \
                test_bug596600.xul \
                window_bug596600.xul \
+               test_bug673301.xul \
                $(NULL)
 endif
 
 ifeq ($(MOZ_WIDGET_TOOLKIT),windows)
 _CHROME_FILES  += taskbar_previews.xul \
 		window_state_windows.xul \
 		taskbar_progress.xul \
 		test_chrome_context_menus_win.xul \
new file mode 100644
--- /dev/null
+++ b/widget/tests/test_bug673301.xul
@@ -0,0 +1,30 @@
+<?xml version="1.0"?>
+<?xml-stylesheet href="chrome://global/skin" type="text/css"?>
+<?xml-stylesheet href="chrome://mochikit/content/tests/SimpleTest/test.css"
+                 type="text/css"?>
+
+<window xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
+
+<script type="application/javascript" src="chrome://mochikit/content/MochiKit/packed.js"/>
+<script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
+
+<body  xmlns="http://www.w3.org/1999/xhtml">
+<p id="display"></p>
+<div id="content" style="display: none"/>
+</body>
+
+<script type="application/javascript">
+var clipboard = Components.classes["@mozilla.org/widget/clipboard;1"]
+                          .getService(Components.interfaces.nsIClipboard);
+
+var transferable = Components.classes['@mozilla.org/widget/transferable;1']
+                             .createInstance(Components.interfaces.nsITransferable);
+
+transferable.addDataFlavor("text/unicode");
+transferable.setTransferData("text/unicode", document, 4);
+
+clipboard.setData(transferable, null, Components.interfaces.nsIClipboard.kGlobalClipboard);
+
+SimpleTest.ok(true, "Didn't crash setting non-text data for text/unicode type");
+</script>
+</window>