<!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" />
<title>[208163] branches/safari-602-branch/Source/WebCore</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { 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 #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#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>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/208163">208163</a></dd>
<dt>Author</dt> <dd>matthew_hanson@apple.com</dd>
<dt>Date</dt> <dd>2016-10-31 11:43:30 -0700 (Mon, 31 Oct 2016)</dd>
</dl>

<h3>Log Message</h3>
<pre>Merge <a href="http://trac.webkit.org/projects/webkit/changeset/206635">r206635</a> and <a href="http://trac.webkit.org/projects/webkit/changeset/206637">r206637</a>. rdar://problem/28718754</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#branchessafari602branchSourceWebCoreChangeLog">branches/safari-602-branch/Source/WebCore/ChangeLog</a></li>
<li><a href="#branchessafari602branchSourceWebCoreloadercacheCachedImagecpp">branches/safari-602-branch/Source/WebCore/loader/cache/CachedImage.cpp</a></li>
<li><a href="#branchessafari602branchSourceWebCoreloadercacheCachedImageh">branches/safari-602-branch/Source/WebCore/loader/cache/CachedImage.h</a></li>
<li><a href="#branchessafari602branchSourceWebCoreloadercacheCachedResourcecpp">branches/safari-602-branch/Source/WebCore/loader/cache/CachedResource.cpp</a></li>
<li><a href="#branchessafari602branchSourceWebCoreloadercacheMemoryCachecpp">branches/safari-602-branch/Source/WebCore/loader/cache/MemoryCache.cpp</a></li>
<li><a href="#branchessafari602branchSourceWebCoreloadercacheMemoryCacheh">branches/safari-602-branch/Source/WebCore/loader/cache/MemoryCache.h</a></li>
<li><a href="#branchessafari602branchSourceWebCoreplatformgraphicsBitmapImagecpp">branches/safari-602-branch/Source/WebCore/platform/graphics/BitmapImage.cpp</a></li>
<li><a href="#branchessafari602branchSourceWebCoreplatformgraphicsImageObserverh">branches/safari-602-branch/Source/WebCore/platform/graphics/ImageObserver.h</a></li>
<li><a href="#branchessafari602branchSourceWebCoreplatformgraphicscgPDFDocumentImagecpp">branches/safari-602-branch/Source/WebCore/platform/graphics/cg/PDFDocumentImage.cpp</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="branchessafari602branchSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: branches/safari-602-branch/Source/WebCore/ChangeLog (208162 => 208163)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-602-branch/Source/WebCore/ChangeLog        2016-10-31 18:43:25 UTC (rev 208162)
+++ branches/safari-602-branch/Source/WebCore/ChangeLog        2016-10-31 18:43:30 UTC (rev 208163)
</span><span class="lines">@@ -1,5 +1,60 @@
</span><span class="cx"> 2016-10-31  Matthew Hanson  &lt;matthew_hanson@apple.com&gt;
</span><span class="cx"> 
</span><ins>+        Merge r206635 and r206637. rdar://problem/28718754
+
+    2016-10-28  Said Abou-Hallawa  &lt;sabouhallawa@apple.com&gt;
+
+            Change the MemoryCache and CachedResource adjustSize functions to take a long argument
+            https://bugs.webkit.org/show_bug.cgi?id=162708
+
+            Reviewed by Brent Fulgham.
+
+            Because the MemoryCache stores the size of the cached memory in unsigned,
+            two problems my happen when reporting a change in the size of the memory:
+
+            1. Signed integer overflow -- which can happen because MemoryCache::adjustSize()
+               takes a signed integer argument. If the allocated or the freed memory size is
+               larger than the maximum of a signed integer, an overflow will happen.
+               For the image caching code, this can be seen where the unsigned decodedSize
+               is casted to an integer before passing it to ImageObserver::decodedSizeChanged().
+
+            2. Unsigned integer overflow -- which can happen if the new allocated memory
+               size plus the currentSize exceeds the maximum of unsigned.
+               This can be seen in MemoryCache::adjustSize() where we add delta to m_liveSize
+               or m_deadSize without checking whether this addition will overflow or not. We
+               do not assert for overflow although we assert for underflow.
+
+            The fix for these two problems can be the following:
+
+            1. Make all the adjustSize functions all the way till MemoryCache::adjustSize()
+               take a signed long integer argument.
+
+            2. Do not create a NativeImagePtr for an ImageFrame if its frameBytes plus the
+               ImageFrameCache::decodedSize() will exceed the maximum of an unsigned integer.
+
+            * loader/cache/CachedImage.cpp:
+            (WebCore::CachedImage::decodedSizeChanged): Change the argument to be long. No overflow will happen when casting the argument from unsigned to long.
+            * loader/cache/CachedImage.h:
+            * loader/cache/CachedResource.cpp:
+            (WebCore::CachedResource::setDecodedSize): Use long integer casting when calling MemoryCache::adjustSize().
+            (WebCore::CachedResource::setEncodedSize): Ditto.
+            * loader/cache/MemoryCache.cpp:
+            (WebCore::MemoryCache::MemoryCache): Add as static assert to ensure sizeof(long long) can hold any unsigned or its negation.
+            (WebCore::MemoryCache::revalidationSucceeded): Use long integer casting when calling MemoryCache::adjustSize().
+            (WebCore::MemoryCache::remove): Ditto.
+            (WebCore::MemoryCache::adjustSize): Change the function argument to long integer. No overflow will happen when casting the argument from unsigned to long.
+            * loader/cache/MemoryCache.h:
+            * platform/graphics/BitmapImage.cpp:
+            (WebCore::BitmapImage::destroyMetadataAndNotify): Use long long casting when calling ImageObserver::decodedSizeChanged().
+            (WebCore::BitmapImage::cacheFrame): Do not create the NativeImage if adding its frameByes to the MemoryCache will cause numerical overflow.
+            (WebCore::BitmapImage::didDecodeProperties): Use long long casting.
+            (WebCore::BitmapImage::frameImageAtIndex): Use long long casting when calling ImageObserver::decodedSizeChanged().
+            * platform/graphics/ImageObserver.h:
+            * platform/graphics/cg/PDFDocumentImage.cpp:
+            (WebCore::PDFDocumentImage::decodedSizeChanged): Use long long casting when calling ImageObserver::decodedSizeChanged().
+
+2016-10-31  Matthew Hanson  &lt;matthew_hanson@apple.com&gt;
+
</ins><span class="cx">         Merge r206802. rdar://problem/28409525
</span><span class="cx"> 
</span><span class="cx">     2016-10-28  Said Abou-Hallawa  &lt;sabouhallawa@apple.com&gt;
</span></span></pre></div>
<a id="branchessafari602branchSourceWebCoreloadercacheCachedImagecpp"></a>
<div class="modfile"><h4>Modified: branches/safari-602-branch/Source/WebCore/loader/cache/CachedImage.cpp (208162 => 208163)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-602-branch/Source/WebCore/loader/cache/CachedImage.cpp        2016-10-31 18:43:25 UTC (rev 208162)
+++ branches/safari-602-branch/Source/WebCore/loader/cache/CachedImage.cpp        2016-10-31 18:43:30 UTC (rev 208163)
</span><span class="lines">@@ -463,11 +463,12 @@
</span><span class="cx">         m_image-&gt;destroyDecodedData();
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-void CachedImage::decodedSizeChanged(const Image* image, int delta)
</del><ins>+void CachedImage::decodedSizeChanged(const Image* image, long long delta)
</ins><span class="cx"> {
</span><span class="cx">     if (!image || image != m_image)
</span><span class="cx">         return;
</span><del>-    
</del><ins>+
+    ASSERT(delta &gt;= 0 || decodedSize() + delta &gt;= 0);
</ins><span class="cx">     setDecodedSize(decodedSize() + delta);
</span><span class="cx"> }
</span><span class="cx"> 
</span></span></pre></div>
<a id="branchessafari602branchSourceWebCoreloadercacheCachedImageh"></a>
<div class="modfile"><h4>Modified: branches/safari-602-branch/Source/WebCore/loader/cache/CachedImage.h (208162 => 208163)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-602-branch/Source/WebCore/loader/cache/CachedImage.h        2016-10-31 18:43:25 UTC (rev 208162)
+++ branches/safari-602-branch/Source/WebCore/loader/cache/CachedImage.h        2016-10-31 18:43:30 UTC (rev 208163)
</span><span class="lines">@@ -117,7 +117,7 @@
</span><span class="cx">     bool stillNeedsLoad() const override { return !errorOccurred() &amp;&amp; status() == Unknown &amp;&amp; !isLoading(); }
</span><span class="cx"> 
</span><span class="cx">     // ImageObserver
</span><del>-    void decodedSizeChanged(const Image*, int delta) override;
</del><ins>+    void decodedSizeChanged(const Image*, long long delta) override;
</ins><span class="cx">     void didDraw(const Image*) override;
</span><span class="cx"> 
</span><span class="cx">     void animationAdvanced(const Image*) override;
</span></span></pre></div>
<a id="branchessafari602branchSourceWebCoreloadercacheCachedResourcecpp"></a>
<div class="modfile"><h4>Modified: branches/safari-602-branch/Source/WebCore/loader/cache/CachedResource.cpp (208162 => 208163)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-602-branch/Source/WebCore/loader/cache/CachedResource.cpp        2016-10-31 18:43:25 UTC (rev 208162)
+++ branches/safari-602-branch/Source/WebCore/loader/cache/CachedResource.cpp        2016-10-31 18:43:30 UTC (rev 208163)
</span><span class="lines">@@ -570,15 +570,15 @@
</span><span class="cx">     if (size == m_decodedSize)
</span><span class="cx">         return;
</span><span class="cx"> 
</span><del>-    int delta = size - m_decodedSize;
</del><ins>+    long long delta = static_cast&lt;long long&gt;(size) - m_decodedSize;
</ins><span class="cx"> 
</span><span class="cx">     // The object must be moved to a different queue, since its size has been changed.
</span><span class="cx">     // Remove before updating m_decodedSize, so we find the resource in the correct LRU list.
</span><span class="cx">     if (allowsCaching() &amp;&amp; inCache())
</span><span class="cx">         MemoryCache::singleton().removeFromLRUList(*this);
</span><del>-    
</del><ins>+
</ins><span class="cx">     m_decodedSize = size;
</span><del>-   
</del><ins>+
</ins><span class="cx">     if (allowsCaching() &amp;&amp; inCache()) {
</span><span class="cx">         auto&amp; memoryCache = MemoryCache::singleton();
</span><span class="cx">         // Now insert into the new LRU list.
</span><span class="lines">@@ -607,7 +607,7 @@
</span><span class="cx">     if (size == m_encodedSize)
</span><span class="cx">         return;
</span><span class="cx"> 
</span><del>-    int delta = size - m_encodedSize;
</del><ins>+    long long delta = static_cast&lt;long long&gt;(size) - m_encodedSize;
</ins><span class="cx"> 
</span><span class="cx">     // The object must be moved to a different queue, since its size has been changed.
</span><span class="cx">     // Remove before updating m_encodedSize, so we find the resource in the correct LRU list.
</span></span></pre></div>
<a id="branchessafari602branchSourceWebCoreloadercacheMemoryCachecpp"></a>
<div class="modfile"><h4>Modified: branches/safari-602-branch/Source/WebCore/loader/cache/MemoryCache.cpp (208162 => 208163)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-602-branch/Source/WebCore/loader/cache/MemoryCache.cpp        2016-10-31 18:43:25 UTC (rev 208162)
+++ branches/safari-602-branch/Source/WebCore/loader/cache/MemoryCache.cpp        2016-10-31 18:43:30 UTC (rev 208163)
</span><span class="lines">@@ -71,6 +71,7 @@
</span><span class="cx">     , m_deadSize(0)
</span><span class="cx">     , m_pruneTimer(*this, &amp;MemoryCache::prune)
</span><span class="cx"> {
</span><ins>+    static_assert(sizeof(long long) &gt; sizeof(unsigned), &quot;Numerical overflow can happen when adjusting the size of the cached memory.&quot;);
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> auto MemoryCache::sessionResourceMap(SessionID sessionID) const -&gt; CachedResourceMap*
</span><span class="lines">@@ -148,7 +149,7 @@
</span><span class="cx">     resource.setInCache(true);
</span><span class="cx">     resource.updateResponseAfterRevalidation(response);
</span><span class="cx">     insertInLRUList(resource);
</span><del>-    int delta = resource.size();
</del><ins>+    long long delta = resource.size();
</ins><span class="cx">     if (resource.decodedSize() &amp;&amp; resource.hasClients())
</span><span class="cx">         insertInLiveDecodedResourcesList(resource);
</span><span class="cx">     if (delta)
</span><span class="lines">@@ -448,7 +449,7 @@
</span><span class="cx">             // Remove from the appropriate LRU list.
</span><span class="cx">             removeFromLRUList(resource);
</span><span class="cx">             removeFromLiveDecodedResourcesList(resource);
</span><del>-            adjustSize(resource.hasClients(), -static_cast&lt;int&gt;(resource.size()));
</del><ins>+            adjustSize(resource.hasClients(), -static_cast&lt;long long&gt;(resource.size()));
</ins><span class="cx">         } else
</span><span class="cx">             ASSERT(resources-&gt;get(key) != &amp;resource);
</span><span class="cx">     }
</span><span class="lines">@@ -641,13 +642,13 @@
</span><span class="cx">     m_deadSize += resource.size();
</span><span class="cx"> }
</span><span class="cx"> 
</span><del>-void MemoryCache::adjustSize(bool live, int delta)
</del><ins>+void MemoryCache::adjustSize(bool live, long long delta)
</ins><span class="cx"> {
</span><span class="cx">     if (live) {
</span><del>-        ASSERT(delta &gt;= 0 || ((int)m_liveSize + delta &gt;= 0));
</del><ins>+        ASSERT(delta &gt;= 0 || (static_cast&lt;long long&gt;(m_liveSize) + delta &gt;= 0));
</ins><span class="cx">         m_liveSize += delta;
</span><span class="cx">     } else {
</span><del>-        ASSERT(delta &gt;= 0 || ((int)m_deadSize + delta &gt;= 0));
</del><ins>+        ASSERT(delta &gt;= 0 || (static_cast&lt;long long&gt;(m_deadSize) + delta &gt;= 0));
</ins><span class="cx">         m_deadSize += delta;
</span><span class="cx">     }
</span><span class="cx"> }
</span></span></pre></div>
<a id="branchessafari602branchSourceWebCoreloadercacheMemoryCacheh"></a>
<div class="modfile"><h4>Modified: branches/safari-602-branch/Source/WebCore/loader/cache/MemoryCache.h (208162 => 208163)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-602-branch/Source/WebCore/loader/cache/MemoryCache.h        2016-10-31 18:43:25 UTC (rev 208162)
+++ branches/safari-602-branch/Source/WebCore/loader/cache/MemoryCache.h        2016-10-31 18:43:30 UTC (rev 208163)
</span><span class="lines">@@ -133,7 +133,7 @@
</span><span class="cx">     void removeFromLRUList(CachedResource&amp;);
</span><span class="cx"> 
</span><span class="cx">     // Called to adjust the cache totals when a resource changes size.
</span><del>-    void adjustSize(bool live, int delta);
</del><ins>+    void adjustSize(bool live, long long delta);
</ins><span class="cx"> 
</span><span class="cx">     // Track decoded resources that are in the cache and referenced by a Web page.
</span><span class="cx">     void insertInLiveDecodedResourcesList(CachedResource&amp;);
</span></span></pre></div>
<a id="branchessafari602branchSourceWebCoreplatformgraphicsBitmapImagecpp"></a>
<div class="modfile"><h4>Modified: branches/safari-602-branch/Source/WebCore/platform/graphics/BitmapImage.cpp (208162 => 208163)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-602-branch/Source/WebCore/platform/graphics/BitmapImage.cpp        2016-10-31 18:43:25 UTC (rev 208162)
+++ branches/safari-602-branch/Source/WebCore/platform/graphics/BitmapImage.cpp        2016-10-31 18:43:30 UTC (rev 208163)
</span><span class="lines">@@ -174,7 +174,7 @@
</span><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     if (frameBytesCleared &amp;&amp; imageObserver())
</span><del>-        imageObserver()-&gt;decodedSizeChanged(this, -safeCast&lt;int&gt;(frameBytesCleared));
</del><ins>+        imageObserver()-&gt;decodedSizeChanged(this, -safeCast&lt;long long&gt;(frameBytesCleared));
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> void BitmapImage::cacheFrame(size_t index, SubsamplingLevel subsamplingLevel, ImageFrameCaching frameCaching)
</span><span class="lines">@@ -186,8 +186,13 @@
</span><span class="cx">         m_frames.grow(numFrames);
</span><span class="cx"> 
</span><span class="cx">     if (frameCaching == CacheMetadataAndFrame) {
</span><del>-        m_frames[index].m_image = m_source.createFrameImageAtIndex(index, subsamplingLevel);
-        m_frames[index].m_subsamplingLevel = subsamplingLevel;
</del><ins>+        size_t frameBytes = size().area() * sizeof(RGBA32);
+
+        // Do not create the NativeImage if adding its frameByes to the MemoryCache will cause numerical overflow.
+        if (WTF::isInBounds&lt;unsigned&gt;(frameBytes + decodedSize())) {
+            m_frames[index].m_image = m_source.createFrameImageAtIndex(index, subsamplingLevel);
+            m_frames[index].m_subsamplingLevel = subsamplingLevel;
+        }
</ins><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     m_frames[index].m_orientation = m_source.orientationAtIndex(index);
</span><span class="lines">@@ -203,11 +208,11 @@
</span><span class="cx">     LOG(Images, &quot;BitmapImage %p cacheFrame %lu (%s%u bytes, complete %d)&quot;, this, index, frameCaching == CacheMetadataOnly ? &quot;metadata only, &quot; : &quot;&quot;, m_frames[index].m_frameBytes, m_frames[index].m_isComplete);
</span><span class="cx"> 
</span><span class="cx">     if (m_frames[index].m_image) {
</span><del>-        int deltaBytes = safeCast&lt;int&gt;(m_frames[index].m_frameBytes);
-        m_decodedSize += deltaBytes;
</del><ins>+        unsigned decodedSize = m_frames[index].m_frameBytes;
+        m_decodedSize += decodedSize;
</ins><span class="cx">         // The fully-decoded frame will subsume the partially decoded data used
</span><span class="cx">         // to determine image properties.
</span><del>-        deltaBytes -= m_decodedPropertiesSize;
</del><ins>+        long long deltaBytes = static_cast&lt;long long&gt;(decodedSize) - m_decodedPropertiesSize;
</ins><span class="cx">         m_decodedPropertiesSize = 0;
</span><span class="cx">         if (imageObserver())
</span><span class="cx">             imageObserver()-&gt;decodedSizeChanged(this, deltaBytes);
</span><span class="lines">@@ -219,17 +224,17 @@
</span><span class="cx">     if (m_decodedSize)
</span><span class="cx">         return;
</span><span class="cx"> 
</span><del>-    size_t updatedSize = m_source.bytesDecodedToDetermineProperties();
-    if (m_decodedPropertiesSize == updatedSize)
</del><ins>+    size_t decodedPropertiesSize = m_source.bytesDecodedToDetermineProperties();
+    if (m_decodedPropertiesSize == decodedPropertiesSize)
</ins><span class="cx">         return;
</span><span class="cx"> 
</span><del>-    int deltaBytes = updatedSize - m_decodedPropertiesSize;
</del><ins>+    long long deltaBytes = static_cast&lt;long long&gt;(decodedPropertiesSize) - m_decodedPropertiesSize;
</ins><span class="cx"> #if !ASSERT_DISABLED
</span><del>-    bool overflow = updatedSize &gt; m_decodedPropertiesSize &amp;&amp; deltaBytes &lt; 0;
-    bool underflow = updatedSize &lt; m_decodedPropertiesSize &amp;&amp; deltaBytes &gt; 0;
</del><ins>+    bool overflow = decodedPropertiesSize &gt; m_decodedPropertiesSize &amp;&amp; deltaBytes &lt; 0;
+    bool underflow = decodedPropertiesSize &lt; m_decodedPropertiesSize &amp;&amp; deltaBytes &gt; 0;
</ins><span class="cx">     ASSERT(!overflow &amp;&amp; !underflow);
</span><span class="cx"> #endif
</span><del>-    m_decodedPropertiesSize = updatedSize;
</del><ins>+    m_decodedPropertiesSize = decodedPropertiesSize;
</ins><span class="cx">     if (imageObserver())
</span><span class="cx">         imageObserver()-&gt;decodedSizeChanged(this, deltaBytes);
</span><span class="cx"> }
</span><span class="lines">@@ -390,12 +395,12 @@
</span><span class="cx">     // re-decode with a lower level.
</span><span class="cx">     if (index &lt; m_frames.size() &amp;&amp; m_frames[index].m_image &amp;&amp; subsamplingLevel &lt; m_frames[index].m_subsamplingLevel) {
</span><span class="cx">         // If the image is already cached, but at too small a size, re-decode a larger version.
</span><del>-        int sizeChange = -m_frames[index].m_frameBytes;
</del><ins>+        unsigned decodedSize = m_frames[index].m_frameBytes;
</ins><span class="cx">         m_frames[index].clear(true);
</span><span class="cx">         invalidatePlatformData();
</span><del>-        m_decodedSize += sizeChange;
</del><ins>+        m_decodedSize -= decodedSize;
</ins><span class="cx">         if (imageObserver())
</span><del>-            imageObserver()-&gt;decodedSizeChanged(this, sizeChange);
</del><ins>+            imageObserver()-&gt;decodedSizeChanged(this, -static_cast&lt;long long&gt;(decodedSize));
</ins><span class="cx">     }
</span><span class="cx"> 
</span><span class="cx">     // If we haven't fetched a frame yet, do so.
</span></span></pre></div>
<a id="branchessafari602branchSourceWebCoreplatformgraphicsImageObserverh"></a>
<div class="modfile"><h4>Modified: branches/safari-602-branch/Source/WebCore/platform/graphics/ImageObserver.h (208162 => 208163)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-602-branch/Source/WebCore/platform/graphics/ImageObserver.h        2016-10-31 18:43:25 UTC (rev 208162)
+++ branches/safari-602-branch/Source/WebCore/platform/graphics/ImageObserver.h        2016-10-31 18:43:30 UTC (rev 208163)
</span><span class="lines">@@ -37,7 +37,7 @@
</span><span class="cx"> protected:
</span><span class="cx">     virtual ~ImageObserver() {}
</span><span class="cx"> public:
</span><del>-    virtual void decodedSizeChanged(const Image*, int delta) = 0;
</del><ins>+    virtual void decodedSizeChanged(const Image*, long long delta) = 0;
</ins><span class="cx">     virtual void didDraw(const Image*) = 0;
</span><span class="cx"> 
</span><span class="cx">     virtual void animationAdvanced(const Image*) = 0;
</span></span></pre></div>
<a id="branchessafari602branchSourceWebCoreplatformgraphicscgPDFDocumentImagecpp"></a>
<div class="modfile"><h4>Modified: branches/safari-602-branch/Source/WebCore/platform/graphics/cg/PDFDocumentImage.cpp (208162 => 208163)</h4>
<pre class="diff"><span>
<span class="info">--- branches/safari-602-branch/Source/WebCore/platform/graphics/cg/PDFDocumentImage.cpp        2016-10-31 18:43:25 UTC (rev 208162)
+++ branches/safari-602-branch/Source/WebCore/platform/graphics/cg/PDFDocumentImage.cpp        2016-10-31 18:43:30 UTC (rev 208163)
</span><span class="lines">@@ -182,7 +182,7 @@
</span><span class="cx">         return;
</span><span class="cx"> 
</span><span class="cx">     if (imageObserver())
</span><del>-        imageObserver()-&gt;decodedSizeChanged(this, -safeCast&lt;int&gt;(m_cachedBytes) + newCachedBytes);
</del><ins>+        imageObserver()-&gt;decodedSizeChanged(this, -safeCast&lt;long long&gt;(m_cachedBytes) + newCachedBytes);
</ins><span class="cx"> 
</span><span class="cx">     ASSERT(s_allDecodedDataSize &gt;= m_cachedBytes);
</span><span class="cx">     // Update with the difference in two steps to avoid unsigned underflow subtraction.
</span></span></pre>
</div>
</div>

</body>
</html>