Title: [160335] trunk/Source/WebCore
- Revision
- 160335
- Author
- simon.fra...@apple.com
- Date
- 2013-12-09 15:27:42 -0800 (Mon, 09 Dec 2013)
Log Message
Avoid divide by zero in scrollbar code, and protect against Obj-C exceptions
https://bugs.webkit.org/show_bug.cgi?id=125469
<rdar://problem/15535772>
Reviewed by Beth Dakin.
In ScrollbarThemeMac::setPaintCharacteristicsForScrollbar(), proportion could
end up as NaN if scrollbar->totalSize() were zero. Protect against that.
Also wrap functions that call into Objective-C with BEGIN_BLOCK_OBJC_EXCEPTIONS/
END_BLOCK_OBJC_EXCEPTIONS.
* platform/mac/ScrollbarThemeMac.mm:
(WebCore::ScrollbarThemeMac::scrollbarThickness):
(WebCore::ScrollbarThemeMac::updateScrollbarOverlayStyle):
(WebCore::ScrollbarThemeMac::minimumThumbLength):
(WebCore::ScrollbarThemeMac::updateEnabledState):
(WebCore::ScrollbarThemeMac::setPaintCharacteristicsForScrollbar):
(WebCore::scrollbarPainterPaint):
Modified Paths
Diff
Modified: trunk/Source/WebCore/ChangeLog (160334 => 160335)
--- trunk/Source/WebCore/ChangeLog 2013-12-09 23:27:18 UTC (rev 160334)
+++ trunk/Source/WebCore/ChangeLog 2013-12-09 23:27:42 UTC (rev 160335)
@@ -1,3 +1,25 @@
+2013-12-09 Simon Fraser <simon.fra...@apple.com>
+
+ Avoid divide by zero in scrollbar code, and protect against Obj-C exceptions
+ https://bugs.webkit.org/show_bug.cgi?id=125469
+ <rdar://problem/15535772>
+
+ Reviewed by Beth Dakin.
+
+ In ScrollbarThemeMac::setPaintCharacteristicsForScrollbar(), proportion could
+ end up as NaN if scrollbar->totalSize() were zero. Protect against that.
+
+ Also wrap functions that call into Objective-C with BEGIN_BLOCK_OBJC_EXCEPTIONS/
+ END_BLOCK_OBJC_EXCEPTIONS.
+
+ * platform/mac/ScrollbarThemeMac.mm:
+ (WebCore::ScrollbarThemeMac::scrollbarThickness):
+ (WebCore::ScrollbarThemeMac::updateScrollbarOverlayStyle):
+ (WebCore::ScrollbarThemeMac::minimumThumbLength):
+ (WebCore::ScrollbarThemeMac::updateEnabledState):
+ (WebCore::ScrollbarThemeMac::setPaintCharacteristicsForScrollbar):
+ (WebCore::scrollbarPainterPaint):
+
2013-12-09 Ryosuke Niwa <rn...@webkit.org>
Implement Document.cloneNode()
Modified: trunk/Source/WebCore/platform/mac/ScrollbarThemeMac.mm (160334 => 160335)
--- trunk/Source/WebCore/platform/mac/ScrollbarThemeMac.mm 2013-12-09 23:27:18 UTC (rev 160334)
+++ trunk/Source/WebCore/platform/mac/ScrollbarThemeMac.mm 2013-12-09 23:27:42 UTC (rev 160335)
@@ -26,6 +26,7 @@
#include "config.h"
#include "ScrollbarThemeMac.h"
+#include "BlockExceptions.h"
#include "ColorMac.h"
#include "ImageBuffer.h"
#include "GraphicsLayer.h"
@@ -221,10 +222,12 @@
int ScrollbarThemeMac::scrollbarThickness(ScrollbarControlSize controlSize)
{
+ BEGIN_BLOCK_OBJC_EXCEPTIONS;
ScrollbarPainter scrollbarPainter = [NSClassFromString(@"NSScrollerImp") scrollerImpWithStyle:recommendedScrollerStyle() controlSize:controlSize horizontal:NO replacingScrollerImp:nil];
if (supportsExpandedScrollbars())
[scrollbarPainter setExpanded:YES];
return [scrollbarPainter trackBoxWidth];
+ END_BLOCK_OBJC_EXCEPTIONS;
}
bool ScrollbarThemeMac::usesOverlayScrollbars() const
@@ -239,6 +242,7 @@
void ScrollbarThemeMac::updateScrollbarOverlayStyle(ScrollbarThemeClient* scrollbar)
{
+ BEGIN_BLOCK_OBJC_EXCEPTIONS;
ScrollbarPainter painter = painterForScrollbar(scrollbar);
switch (scrollbar->scrollbarOverlayStyle()) {
case ScrollbarOverlayStyleDefault:
@@ -251,6 +255,7 @@
[painter setKnobStyle:NSScrollerKnobStyleLight];
break;
}
+ END_BLOCK_OBJC_EXCEPTIONS;
}
double ScrollbarThemeMac::initialAutoscrollTimerDelay()
@@ -420,7 +425,9 @@
int ScrollbarThemeMac::minimumThumbLength(ScrollbarThemeClient* scrollbar)
{
+ BEGIN_BLOCK_OBJC_EXCEPTIONS;
return [scrollbarMap()->get(scrollbar) knobMinLength];
+ END_BLOCK_OBJC_EXCEPTIONS;
}
bool ScrollbarThemeMac::shouldCenterOnThumb(ScrollbarThemeClient*, const PlatformMouseEvent& evt)
@@ -457,26 +464,31 @@
void ScrollbarThemeMac::updateEnabledState(ScrollbarThemeClient* scrollbar)
{
+ BEGIN_BLOCK_OBJC_EXCEPTIONS;
[scrollbarMap()->get(scrollbar) setEnabled:scrollbar->enabled()];
+ END_BLOCK_OBJC_EXCEPTIONS;
}
void ScrollbarThemeMac::setPaintCharacteristicsForScrollbar(ScrollbarThemeClient* scrollbar)
{
+ BEGIN_BLOCK_OBJC_EXCEPTIONS;
ScrollbarPainter painter = painterForScrollbar(scrollbar);
float value;
float overhang;
ScrollableArea::computeScrollbarValueAndOverhang(scrollbar->currentPos(), scrollbar->totalSize(), scrollbar->visibleSize(), value, overhang);
- float proportion = (static_cast<CGFloat>(scrollbar->visibleSize()) - overhang) / scrollbar->totalSize();
+ float proportion = scrollbar->totalSize() > 0 ? (static_cast<CGFloat>(scrollbar->visibleSize()) - overhang) / scrollbar->totalSize() : 1;
[painter setEnabled:scrollbar->enabled()];
[painter setBoundsSize:scrollbar->frameRect().size()];
[painter setDoubleValue:value];
[painter setKnobProportion:proportion];
+ END_BLOCK_OBJC_EXCEPTIONS;
}
static void scrollbarPainterPaint(ScrollbarPainter scrollbarPainter, bool enabled)
{
+ BEGIN_BLOCK_OBJC_EXCEPTIONS;
// Use rectForPart: here; it will take the expansion transition progress into account.
NSRect trackRect = [scrollbarPainter rectForPart:NSScrollerKnobSlot];
[scrollbarPainter drawKnobSlotInRect:trackRect highlight:NO];
@@ -485,6 +497,7 @@
// call drawKnob.
if (enabled)
[scrollbarPainter drawKnob];
+ END_BLOCK_OBJC_EXCEPTIONS;
}
bool ScrollbarThemeMac::paint(ScrollbarThemeClient* scrollbar, GraphicsContext* context, const IntRect& damageRect)
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes