Changeset 206635 in webkit
- Timestamp:
- Sep 30, 2016, 9:01:36 AM (9 years ago)
- Location:
- trunk
- Files:
-
- 13 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/LayoutTests/ChangeLog
r206634 r206635 1 2016-09-30 Said Abou-Hallawa <sabouhallawa@apple.com> 2 3 Change the MemoryCache and CachedResource adjustSize functions to take a long argument 4 https://bugs.webkit.org/show_bug.cgi?id=162708 5 <rdar://problem/28555702> 6 7 Reviewed by Brent Fulgham. 8 9 * TestExpectations: Remove failed tests. 10 1 11 2016-09-30 Chris Dumez <cdumez@apple.com> 2 12 -
trunk/LayoutTests/TestExpectations
r206602 r206635 986 986 # Only iOS has implemented lettepress. 987 987 fast/text/letterpress-different.html [ ImageOnlyFailure ] 988 989 webkit.org/b/162696 [ Release ] fast/images/paletted-png-with-color-profile.html [ Crash ]990 webkit.org/b/162696 [ Release ] fast/images/paint-subrect.html [ Crash ]991 webkit.org/b/162696 [ Release ] fast/images/paint-subrect-grid.html [ Crash ]992 webkit.org/b/162696 [ Release ] fast/images/pdf-as-image-crop-box.html [ Crash ]993 webkit.org/b/162696 [ Release ] fast/images/link-body-content-imageDimensionChanged-crash.html [ Crash ]994 webkit.org/b/162696 [ Release ] fast/images/object-data-url-case-insensitivity.html [ Crash ]995 webkit.org/b/162696 [ Release ] fast/images/move-image-to-new-document.html [ Crash ]996 webkit.org/b/162696 [ Release ] fast/images/pdf-as-background.html [ Crash ]997 webkit.org/b/162696 [ Release ] fast/images/pdf-as-image-landscape.html [ Crash ]998 webkit.org/b/162696 [ Release ] fast/images/pdf-as-image-with-annotations-expected.html [ Crash ]999 webkit.org/b/162696 [ Release ] fast/images/pdf-as-image-too-big.html [ Crash ]1000 webkit.org/b/162696 [ Release ] fast/images/object-image.html [ Crash ]1001 webkit.org/b/162696 [ Release ] fast/images/pdf-as-image-with-annotations.html [ Crash ]1002 webkit.org/b/162696 [ Release ] fast/images/load-img-with-empty-src.html [ Crash ] -
trunk/Source/WebCore/ChangeLog
r206634 r206635 1 2016-09-30 Said Abou-Hallawa <sabouhallawa@apple.com> 2 3 Change the MemoryCache and CachedResource adjustSize functions to take a long argument 4 https://bugs.webkit.org/show_bug.cgi?id=162708 5 <rdar://problem/28555702> 6 7 Reviewed by Brent Fulgham. 8 9 Because the MemoryCache stores the size of the cached memory in unsigned, 10 two problems my happen when reporting a change in the size of the memory: 11 12 1. Signed integer overflow -- which can happen because MemoryCache::adjustSize() 13 takes a signed integer argument. If the allocated or the freed memory size is 14 larger than the maximum of a signed integer, an overflow will happen. 15 For the image caching code, this can be seen where the unsigned decodedSize 16 is casted to an integer before passing it to ImageObserver::decodedSizeChanged(). 17 18 2. Unsigned integer overflow -- which can happen if the new allocated memory 19 size plus the currentSize exceeds the maximum of unsigned. 20 This can be seen in MemoryCache::adjustSize() where we add delta to m_liveSize 21 or m_deadSize without checking whether this addition will overflow or not. We 22 do not assert for overflow although we assert for underflow. 23 24 The fix for these two problems can be the following: 25 26 1. Make all the adjustSize functions all the way till MemoryCache::adjustSize() 27 take a signed long integer argument. 28 29 2. Do not create a NativeImagePtr for an ImageFrame if its frameBytes plus the 30 ImageFrameCache::decodedSize() will exceed the maximum of an unsigned integer. 31 32 * loader/cache/CachedImage.cpp: 33 (WebCore::CachedImage::decodedSizeChanged): Change the argument to be long. No overflow will happen when casting the argument from unsigned to long. 34 * loader/cache/CachedImage.h: 35 * loader/cache/CachedResource.cpp: 36 (WebCore::CachedResource::setDecodedSize): Use long integer casting when calling MemoryCache::adjustSize(). 37 (WebCore::CachedResource::setEncodedSize): Ditto. 38 * loader/cache/MemoryCache.cpp: 39 (WebCore::MemoryCache::MemoryCache): Add as static assert to ensure sizeof(long long) can hold any unsigned or its negation. 40 (WebCore::MemoryCache::revalidationSucceeded): Use long integer casting when calling MemoryCache::adjustSize(). 41 (WebCore::MemoryCache::remove): Ditto. 42 (WebCore::MemoryCache::adjustSize): Change the function argument to long integer. No overflow will happen when casting the argument from unsigned to long. 43 * loader/cache/MemoryCache.h: 44 * platform/graphics/ImageFrameCache.cpp: 45 (WebCore::ImageFrameCache::destroyIncompleteDecodedData): Call a function with its new name. 46 (WebCore::ImageFrameCache::decodedSizeChanged): Change the function argument to long integer. No overflow will happen when casting the argument from unsigned to long. 47 (WebCore::ImageFrameCache::decodedSizeIncreased): Use long integer casting when calling decodedSizeChanged(). 48 (WebCore::ImageFrameCache::decodedSizeDecreased): Ditto. 49 (WebCore::ImageFrameCache::decodedSizeReset): Ditto. 50 (WebCore::ImageFrameCache::didDecodeProperties): Ditto. 51 (WebCore::ImageFrameCache::frameAtIndex): Do not create the NativeImage if adding its frameByes to the MemoryCache will cause numerical overflow. 52 (WebCore::ImageFrameCache::decodedSizeIncremented): Deleted. This function is renamed decodedSizeIncreased(). 53 (WebCore::ImageFrameCache::decodedSizeDecremented): Deleted. This function is renamed decodedSizeDecreased(). 54 * platform/graphics/ImageFrameCache.h: 55 * platform/graphics/ImageObserver.h: 56 * platform/graphics/IntSize.h: 57 (WebCore::IntSize::unclampedArea): Returns the area of an IntSize in size_t. 58 * platform/graphics/cg/PDFDocumentImage.cpp: 59 (WebCore::PDFDocumentImage::decodedSizeChanged): Use long integer casting when calling ImageObserver::decodedSizeChanged(). 60 1 61 2016-09-30 Chris Dumez <cdumez@apple.com> 2 62 -
trunk/Source/WebCore/loader/cache/CachedImage.cpp
r206435 r206635 451 451 } 452 452 453 void CachedImage::decodedSizeChanged(const Image* image, intdelta)453 void CachedImage::decodedSizeChanged(const Image* image, long long delta) 454 454 { 455 455 if (!image || image != m_image) 456 456 return; 457 457 458 ASSERT(delta >= 0 || decodedSize() + delta >= 0); 458 459 setDecodedSize(decodedSize() + delta); 459 460 } -
trunk/Source/WebCore/loader/cache/CachedImage.h
r206435 r206635 119 119 120 120 // ImageObserver 121 void decodedSizeChanged(const Image*, intdelta) override;121 void decodedSizeChanged(const Image*, long long delta) override; 122 122 void didDraw(const Image*) override; 123 123 -
trunk/Source/WebCore/loader/cache/CachedResource.cpp
r206370 r206635 650 650 return; 651 651 652 int delta = size- m_decodedSize;652 long long delta = static_cast<long long>(size) - m_decodedSize; 653 653 654 654 // The object must be moved to a different queue, since its size has been changed. … … 656 656 if (allowsCaching() && inCache()) 657 657 MemoryCache::singleton().removeFromLRUList(*this); 658 658 659 659 m_decodedSize = size; 660 660 … … 687 687 return; 688 688 689 int delta = size- m_encodedSize;689 long long delta = static_cast<long long>(size) - m_encodedSize; 690 690 691 691 // The object must be moved to a different queue, since its size has been changed. -
trunk/Source/WebCore/loader/cache/MemoryCache.cpp
r206435 r206635 72 72 , m_pruneTimer(*this, &MemoryCache::prune) 73 73 { 74 static_assert(sizeof(long long) > sizeof(unsigned), "Numerical overflow can happen when adjusting the size of the cached memory."); 74 75 } 75 76 … … 149 150 resource.updateResponseAfterRevalidation(response); 150 151 insertInLRUList(resource); 151 intdelta = resource.size();152 long long delta = resource.size(); 152 153 if (resource.decodedSize() && resource.hasClients()) 153 154 insertInLiveDecodedResourcesList(resource); … … 449 450 removeFromLRUList(resource); 450 451 removeFromLiveDecodedResourcesList(resource); 451 adjustSize(resource.hasClients(), -static_cast< int>(resource.size()));452 adjustSize(resource.hasClients(), -static_cast<long long>(resource.size())); 452 453 } else 453 454 ASSERT(resources->get(key) != &resource); … … 642 643 } 643 644 644 void MemoryCache::adjustSize(bool live, intdelta)645 void MemoryCache::adjustSize(bool live, long long delta) 645 646 { 646 647 if (live) { 647 ASSERT(delta >= 0 || ( (int)m_liveSize+ delta >= 0));648 ASSERT(delta >= 0 || (static_cast<long long>(m_liveSize) + delta >= 0)); 648 649 m_liveSize += delta; 649 650 } else { 650 ASSERT(delta >= 0 || ( (int)m_deadSize+ delta >= 0));651 ASSERT(delta >= 0 || (static_cast<long long>(m_deadSize) + delta >= 0)); 651 652 m_deadSize += delta; 652 653 } -
trunk/Source/WebCore/loader/cache/MemoryCache.h
r205682 r206635 134 134 135 135 // Called to adjust the cache totals when a resource changes size. 136 void adjustSize(bool live, intdelta);136 void adjustSize(bool live, long long delta); 137 137 138 138 // Track decoded resources that are in the cache and referenced by a Web page. -
trunk/Source/WebCore/platform/graphics/ImageFrameCache.cpp
r206481 r206635 36 36 #endif 37 37 38 #include <wtf/CheckedArithmetic.h> 39 40 38 41 namespace WebCore { 39 42 … … 67 70 for (size_t i = 0; i < count; ++i) 68 71 decodedSize += m_frames[i].clearImage(); 69 72 70 73 decodedSizeReset(decodedSize); 71 74 } … … 94 97 decodedSize += frame.clear(); 95 98 } 96 97 decodedSizeDecremented(decodedSize); 98 } 99 100 101 void ImageFrameCache::decodedSizeChanged(int decodedSize) 99 100 decodedSizeDecreased(decodedSize); 101 } 102 103 void ImageFrameCache::decodedSizeChanged(long long decodedSize) 102 104 { 103 105 if (!decodedSize || !m_image || !m_image->imageObserver()) … … 107 109 } 108 110 109 void ImageFrameCache::decodedSizeIncre mented(unsigned decodedSize)111 void ImageFrameCache::decodedSizeIncreased(unsigned decodedSize) 110 112 { 111 113 if (!decodedSize) … … 116 118 // The fully-decoded frame will subsume the partially decoded data used 117 119 // to determine image properties. 118 int changeSize = decodedSize- m_decodedPropertiesSize;120 long long changeSize = static_cast<long long>(decodedSize) - m_decodedPropertiesSize; 119 121 m_decodedPropertiesSize = 0; 120 122 decodedSizeChanged(changeSize); 121 123 } 122 124 123 void ImageFrameCache::decodedSizeDecre mented(unsigned decodedSize)125 void ImageFrameCache::decodedSizeDecreased(unsigned decodedSize) 124 126 { 125 127 if (!decodedSize) 126 128 return; 127 129 128 130 ASSERT(m_decodedSize >= decodedSize); 129 131 m_decodedSize -= decodedSize; 130 decodedSizeChanged(-s afeCast<int>(decodedSize));132 decodedSizeChanged(-static_cast<long long>(decodedSize)); 131 133 } 132 134 … … 135 137 ASSERT(m_decodedSize >= decodedSize); 136 138 m_decodedSize -= decodedSize; 137 139 138 140 // Clearing the ImageSource destroys the extra decoded data used for 139 141 // determining image properties. 140 142 decodedSize += m_decodedPropertiesSize; 141 143 m_decodedPropertiesSize = 0; 142 decodedSizeChanged(-s afeCast<int>(decodedSize));144 decodedSizeChanged(-static_cast<long long>(decodedSize)); 143 145 } 144 146 … … 147 149 if (m_decodedSize) 148 150 return; 149 150 int decodedSize = decodedPropertiesSize- m_decodedPropertiesSize;151 152 long long decodedSize = static_cast<long long>(decodedPropertiesSize) - m_decodedPropertiesSize; 151 153 m_decodedPropertiesSize = decodedPropertiesSize; 152 154 decodedSizeChanged(decodedSize); … … 216 218 if (frame.hasInvalidNativeImage(subsamplingLevel)) { 217 219 unsigned decodedSize = frame.clear(); 218 decodedSizeDecre mented(decodedSize);220 decodedSizeDecreased(decodedSize); 219 221 } 220 222 … … 223 225 224 226 if (!frame.hasNativeImage() && caching == ImageFrame::Caching::MetadataAndImage) { 225 setFrameNativeImage(m_decoder->createFrameImageAtIndex(index, subsamplingLevel), index, subsamplingLevel); 226 decodedSizeIncremented(frame.frameBytes()); 227 size_t frameBytes = size().unclampedArea() * sizeof(RGBA32); 228 229 // Do not create the NativeImage if adding its frameByes to the MemoryCache will cause numerical overflow. 230 if (WTF::isInBounds<unsigned>(frameBytes + decodedSize())) { 231 setFrameNativeImage(m_decoder->createFrameImageAtIndex(index, subsamplingLevel), index, subsamplingLevel); 232 decodedSizeIncreased(frame.frameBytes()); 233 } 227 234 } 228 235 -
trunk/Source/WebCore/platform/graphics/ImageFrameCache.h
r206481 r206635 88 88 89 89 bool isDecoderAvailable() const { return m_decoder; } 90 void decodedSizeChanged( intdecodedSize);90 void decodedSizeChanged(long long decodedSize); 91 91 void didDecodeProperties(unsigned decodedPropertiesSize); 92 void decodedSizeIncre mented(unsigned decodedSize);93 void decodedSizeDecre mented(unsigned decodedSize);92 void decodedSizeIncreased(unsigned decodedSize); 93 void decodedSizeDecreased(unsigned decodedSize); 94 94 void decodedSizeReset(unsigned decodedSize); 95 95 -
trunk/Source/WebCore/platform/graphics/ImageObserver.h
r165676 r206635 38 38 virtual ~ImageObserver() {} 39 39 public: 40 virtual void decodedSizeChanged(const Image*, intdelta) = 0;40 virtual void decodedSizeChanged(const Image*, long long delta) = 0; 41 41 virtual void didDraw(const Image*) = 0; 42 42 -
trunk/Source/WebCore/platform/graphics/IntSize.h
r205881 r206635 137 137 } 138 138 139 size_t unclampedArea() const 140 { 141 return static_cast<size_t>(abs(m_width)) * abs(m_height); 142 } 143 139 144 int diagonalLengthSquared() const 140 145 { -
trunk/Source/WebCore/platform/graphics/cg/PDFDocumentImage.cpp
r206249 r206635 183 183 184 184 if (imageObserver()) 185 imageObserver()->decodedSizeChanged(this, -s afeCast<int>(m_cachedBytes) + newCachedBytes);185 imageObserver()->decodedSizeChanged(this, -static_cast<long long>(m_cachedBytes) + newCachedBytes); 186 186 187 187 ASSERT(s_allDecodedDataSize >= m_cachedBytes);
Note:
See TracChangeset
for help on using the changeset viewer.