<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" /><style type="text/css"><!--
#msg dl { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fc0 solid; padding: 6px; }
#msg ul, pre { overflow: auto; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<title>[20666] branches/Safari-522/WebKit</title>
</head>
<body>

<div id="msg">
<dl>
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/20666">20666</a></dd>
<dt>Author</dt> <dd>bdash</dd>
<dt>Date</dt> <dd>2007-04-02 12:46:59 -0700 (Mon, 02 Apr 2007)</dd>
</dl>

<h3>Log Message</h3>
<pre>Merge r20571.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#branchesSafari522WebKitChangeLog">branches/Safari-522/WebKit/ChangeLog</a></li>
<li><a href="#branchesSafari522WebKitPluginsWebBaseNetscapePluginStreamh">branches/Safari-522/WebKit/Plugins/WebBaseNetscapePluginStream.h</a></li>
<li><a href="#branchesSafari522WebKitPluginsWebBaseNetscapePluginStreamm">branches/Safari-522/WebKit/Plugins/WebBaseNetscapePluginStream.m</a></li>
<li><a href="#branchesSafari522WebKitPluginsWebBaseNetscapePluginViewmm">branches/Safari-522/WebKit/Plugins/WebBaseNetscapePluginView.mm</a></li>
<li><a href="#branchesSafari522WebKitWebKitxcodeprojprojectpbxproj">branches/Safari-522/WebKit/WebKit.xcodeproj/project.pbxproj</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="branchesSafari522WebKitChangeLog"></a>
<div class="modfile"><h4>Modified: branches/Safari-522/WebKit/ChangeLog (20665 => 20666)</h4>
<pre class="diff"><span>
<span class="info">--- branches/Safari-522/WebKit/ChangeLog        2007-04-02 19:37:26 UTC (rev 20665)
+++ branches/Safari-522/WebKit/ChangeLog        2007-04-02 19:46:59 UTC (rev 20666)
</span><span class="lines">@@ -22,6 +22,33 @@
</span><span class="cx">         * Misc/WebKitVersionChecks.h: Remove Acrobat quirk constant.
</span><span class="cx">         * WebView/WebView.mm:
</span><span class="cx">         (-[WebView _updateWebCoreSettingsFromPreferences:]):
</span><ins>+
+2007-03-27  Geoffrey Garen  &lt;ggaren@apple.com&gt;
+
+        Reluctantly tolerated by Darin Adler.
+        
+        Fixed &lt;rdar://problem/5091330&gt; REGRESSION: Repro crash in 
+        -[WebBaseNetscapePluginView(WebNPPCallbacks) destroyStream:reason:] 
+        navigating away from page with DivX movie plug-in (13203)
+        
+        The problem was that the DivX plug-in would ask us to destroy an NPStream
+        that had already been destroyed, causing us to wander off into freed
+        memory. (I believe the reason this was a regression was that we never used 
+        to destroy plug-in streams, period.)
+        
+        The solution here is to track the NPStreams belonging to a plug-in, and 
+        guard against plug-ins making calls with NPStreams that don't belong to 
+        them. (It turns out that NPN_DestroyStream is the only stream-based 
+        plug-in call we support.)
+
+        (CarbonPathFromPOSIXPath): Fixed up a cast to be C++ compatible.
+        * Plugins/WebBaseNetscapePluginView.mm:
+        (-[WebBaseNetscapePluginView destroyStream:reason:]): The actual fix.
+        Use helper method to guard against a plug-in using an NPStream that doesn't
+        belong to it.
+        * WebKit.xcodeproj/project.pbxproj: Made WebBaseNetscapePluginView ObjC++
+        so I could use HashMap.
+
</ins><span class="cx"> 2007-03-28  Adele Peterson  &lt;adele@apple.com&gt;
</span><span class="cx"> 
</span><span class="cx">         Reviewed by Brady.
</span></span></pre></div>
<a id="branchesSafari522WebKitPluginsWebBaseNetscapePluginStreamh"></a>
<div class="modfile"><h4>Modified: branches/Safari-522/WebKit/Plugins/WebBaseNetscapePluginStream.h (20665 => 20666)</h4>
<pre class="diff"><span>
<span class="info">--- branches/Safari-522/WebKit/Plugins/WebBaseNetscapePluginStream.h        2007-04-02 19:37:26 UTC (rev 20665)
+++ branches/Safari-522/WebKit/Plugins/WebBaseNetscapePluginStream.h        2007-04-02 19:46:59 UTC (rev 20666)
</span><span class="lines">@@ -60,7 +60,9 @@
</span><span class="cx">     NPP_URLNotifyProcPtr NPP_URLNotify;
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>++ (NPP)ownerForStream:(WebBaseNetscapePluginStream *)stream;
</ins><span class="cx"> + (NPReason)reasonForError:(NSError *)error;
</span><ins>+
</ins><span class="cx"> - (NSError *)errorForReason:(NPReason)theReason;
</span><span class="cx"> 
</span><span class="cx"> - (id)initWithRequestURL:(NSURL *)theRequestURL
</span></span></pre></div>
<a id="branchesSafari522WebKitPluginsWebBaseNetscapePluginStreamm"></a>
<div class="modfile"><h4>Modified: branches/Safari-522/WebKit/Plugins/WebBaseNetscapePluginStream.m (20665 => 20666)</h4>
<pre class="diff"><span>
<span class="info">--- branches/Safari-522/WebKit/Plugins/WebBaseNetscapePluginStream.m        2007-04-02 19:37:26 UTC (rev 20665)
+++ branches/Safari-522/WebKit/Plugins/WebBaseNetscapePluginStream.m        2007-04-02 19:46:59 UTC (rev 20666)
</span><span class="lines">@@ -26,23 +26,29 @@
</span><span class="cx">  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
</span><span class="cx">  */
</span><span class="cx"> 
</span><del>-#import &lt;WebKit/WebBaseNetscapePluginStream.h&gt;
</del><ins>+#import &quot;WebBaseNetscapePluginStream.h&quot;
</ins><span class="cx"> 
</span><del>-#import &lt;WebKit/WebBaseNetscapePluginView.h&gt;
-#import &lt;WebKit/WebKitErrorsPrivate.h&gt;
-#import &lt;WebKit/WebKitLogging.h&gt;
-#import &lt;WebKit/WebNetscapePluginPackage.h&gt;
-#import &lt;WebKit/WebNSObjectExtras.h&gt;
-#import &lt;WebKit/WebNSURLExtras.h&gt;
</del><ins>+#import &quot;WebBaseNetscapePluginView.h&quot;
+#import &quot;WebKitErrorsPrivate.h&quot;
+#import &quot;WebKitLogging.h&quot;
+#import &quot;WebNSObjectExtras.h&quot;
+#import &quot;WebNSURLExtras.h&quot;
+#import &quot;WebNetscapePluginPackage.h&quot;
+#import &lt;Foundation/NSURLResponse.h&gt;
+#import &lt;WebCore/WebCoreObjCExtras.h&gt;
</ins><span class="cx"> #import &lt;WebKitSystemInterface.h&gt;
</span><ins>+#import &lt;wtf/HashMap.h&gt;
</ins><span class="cx"> 
</span><del>-#import &lt;WebCore/WebCoreObjCExtras.h&gt;
</del><ins>+#define WEB_REASON_NONE -1
</ins><span class="cx"> 
</span><del>-#import &lt;Foundation/NSURLResponse.h&gt;
-
</del><span class="cx"> static char *CarbonPathFromPOSIXPath(const char *posixPath);
</span><span class="cx"> 
</span><del>-#define WEB_REASON_NONE -1
</del><ins>+typedef HashMap&lt;WebBaseNetscapePluginStream *, NPP&gt; StreamMap;
+static StreamMap&amp; streams()
+{
+    static StreamMap staticStreams;
+    return staticStreams;
+}
</ins><span class="cx"> 
</span><span class="cx"> @implementation WebBaseNetscapePluginStream
</span><span class="cx"> 
</span><span class="lines">@@ -53,6 +59,11 @@
</span><span class="cx"> }
</span><span class="cx"> #endif
</span><span class="cx"> 
</span><ins>++ (NPP)ownerForStream:(WebBaseNetscapePluginStream *)stream
+{
+    return streams().get(stream);
+}
+
</ins><span class="cx"> + (NPReason)reasonForError:(NSError *)error
</span><span class="cx"> {
</span><span class="cx">     if (error == nil) {
</span><span class="lines">@@ -105,6 +116,8 @@
</span><span class="cx">     [self setPlugin:thePlugin];
</span><span class="cx">     notifyData = theNotifyData;
</span><span class="cx">     sendNotification = flag;
</span><ins>+
+    streams().add(self, thePlugin);
</ins><span class="cx">     
</span><span class="cx">     isTerminated = NO;
</span><span class="cx">     
</span><span class="lines">@@ -129,6 +142,8 @@
</span><span class="cx">     free((void *)stream.url);
</span><span class="cx">     free(path);
</span><span class="cx"> 
</span><ins>+    streams().remove(self);
+
</ins><span class="cx">     [super dealloc];
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="lines">@@ -144,6 +159,8 @@
</span><span class="cx">     free((void *)stream.url);
</span><span class="cx">     free(path);
</span><span class="cx"> 
</span><ins>+    streams().remove(self);
+
</ins><span class="cx">     [super finalize];
</span><span class="cx"> }
</span><span class="cx"> 
</span><span class="lines">@@ -495,7 +512,7 @@
</span><span class="cx">         CFRelease(url);
</span><span class="cx">         if (hfsPath) {
</span><span class="cx">             CFIndex bufSize = CFStringGetMaximumSizeOfFileSystemRepresentation(hfsPath);
</span><del>-            char *filename = malloc(bufSize);
</del><ins>+            char* filename = static_cast&lt;char*&gt;(malloc(bufSize));
</ins><span class="cx">             CFStringGetFileSystemRepresentation(hfsPath, filename, bufSize);
</span><span class="cx">             CFRelease(hfsPath);
</span><span class="cx">             return filename;
</span></span></pre></div>
<a id="branchesSafari522WebKitPluginsWebBaseNetscapePluginViewmm"></a>
<div class="modfile"><h4>Modified: branches/Safari-522/WebKit/Plugins/WebBaseNetscapePluginView.mm (20665 => 20666)</h4>
<pre class="diff"><span>
<span class="info">--- branches/Safari-522/WebKit/Plugins/WebBaseNetscapePluginView.mm        2007-04-02 19:37:26 UTC (rev 20665)
+++ branches/Safari-522/WebKit/Plugins/WebBaseNetscapePluginView.mm        2007-04-02 19:46:59 UTC (rev 20666)
</span><span class="lines">@@ -2231,10 +2231,15 @@
</span><span class="cx"> -(NPError)destroyStream:(NPStream*)stream reason:(NPReason)reason
</span><span class="cx"> {
</span><span class="cx">     LOG(Plugins, &quot;NPN_DestroyStream&quot;);
</span><del>-    if (!stream-&gt;ndata) {
</del><ins>+    WebBaseNetscapePluginStream *browserStream = static_cast&lt;WebBaseNetscapePluginStream *&gt;(stream-&gt;ndata);
+
+    // This function does a sanity check to ensure that the NPStream provided actually
+    // belongs to the plug-in that provided it, which fixes a crash in the DivX 
+    // plug-in: &lt;rdar://problem/5093862&gt; | http://bugs.webkit.org/show_bug.cgi?id=13203
+    if (!stream || [WebBaseNetscapePluginStream ownerForStream:browserStream] != plugin) {
+        LOG_ERROR(&quot;Invalid NPStream passed to NPN_DestroyStream: %p\n&quot;, stream);
</ins><span class="cx">         return NPERR_INVALID_INSTANCE_ERROR;
</span><span class="cx">     }
</span><del>-    WebBaseNetscapePluginStream *browserStream = (WebBaseNetscapePluginStream *)stream-&gt;ndata;
</del><span class="cx">     [browserStream cancelLoadAndDestroyStreamWithError:[browserStream errorForReason:reason]];
</span><span class="cx">     return NPERR_NO_ERROR;
</span><span class="cx"> }
</span></span></pre></div>
<a id="branchesSafari522WebKitWebKitxcodeprojprojectpbxproj"></a>
<div class="modfile"><h4>Modified: branches/Safari-522/WebKit/WebKit.xcodeproj/project.pbxproj (20665 => 20666)</h4>
<pre class="diff"><span>
<span class="info">--- branches/Safari-522/WebKit/WebKit.xcodeproj/project.pbxproj        2007-04-02 19:37:26 UTC (rev 20665)
+++ branches/Safari-522/WebKit/WebKit.xcodeproj/project.pbxproj        2007-04-02 19:46:59 UTC (rev 20666)
</span><span class="lines">@@ -558,7 +558,7 @@
</span><span class="cx">                 F59EAE410253C8DE018635CA /* WebCoreStatistics.mm */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WebCoreStatistics.mm; sourceTree = &quot;&lt;group&gt;&quot;; tabWidth = 8; usesTabs = 0; };
</span><span class="cx">                 F5A55DC702BAA2E8018635CC /* WebHTMLRepresentationPrivate.h */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 4; lastKnownFileType = sourcecode.c.h; path = WebHTMLRepresentationPrivate.h; sourceTree = &quot;&lt;group&gt;&quot;; tabWidth = 8; usesTabs = 0; };
</span><span class="cx">                 F5A672B90263866E01000102 /* WebBaseNetscapePluginStream.h */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 4; lastKnownFileType = sourcecode.c.h; path = WebBaseNetscapePluginStream.h; sourceTree = &quot;&lt;group&gt;&quot;; tabWidth = 8; usesTabs = 0; };
</span><del>-                F5A672BA0263866E01000102 /* WebBaseNetscapePluginStream.m */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 4; lastKnownFileType = sourcecode.c.objc; path = WebBaseNetscapePluginStream.m; sourceTree = &quot;&lt;group&gt;&quot;; tabWidth = 8; usesTabs = 0; };
</del><ins>+                F5A672BA0263866E01000102 /* WebBaseNetscapePluginStream.m */ = {isa = PBXFileReference; explicitFileType = sourcecode.cpp.objcpp; fileEncoding = 4; indentWidth = 4; path = WebBaseNetscapePluginStream.m; sourceTree = &quot;&lt;group&gt;&quot;; tabWidth = 8; usesTabs = 0; };
</ins><span class="cx">                 F5AEBB3D024A527601C1A526 /* WebPreferences.m */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 4; lastKnownFileType = sourcecode.c.objc; path = WebPreferences.m; sourceTree = &quot;&lt;group&gt;&quot;; tabWidth = 8; usesTabs = 0; };
</span><span class="cx">                 F5AFB45E02B94DC8018635CA /* WebFrameBridge.h */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 4; lastKnownFileType = sourcecode.c.h; path = WebFrameBridge.h; sourceTree = &quot;&lt;group&gt;&quot;; tabWidth = 8; usesTabs = 0; };
</span><span class="cx">                 F5AFB45F02B94DC8018635CA /* WebFrameBridge.mm */ = {isa = PBXFileReference; fileEncoding = 4; indentWidth = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WebFrameBridge.mm; sourceTree = &quot;&lt;group&gt;&quot;; tabWidth = 8; usesTabs = 0; };
</span></span></pre>
</div>
</div>

</body>
</html>