Changeset 160335 in webkit


Ignore:
Timestamp:
Dec 9, 2013, 3:27:42 PM (12 years ago)
Author:
Simon Fraser
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):

Location:
trunk/Source/WebCore
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r160330 r160335  
     12013-12-09  Simon Fraser  <simon.fraser@apple.com>
     2
     3        Avoid divide by zero in scrollbar code, and protect against Obj-C exceptions
     4        https://bugs.webkit.org/show_bug.cgi?id=125469
     5        <rdar://problem/15535772>
     6
     7        Reviewed by Beth Dakin.
     8       
     9        In ScrollbarThemeMac::setPaintCharacteristicsForScrollbar(), proportion could
     10        end up as NaN if scrollbar->totalSize() were zero. Protect against that.
     11       
     12        Also wrap functions that call into Objective-C with BEGIN_BLOCK_OBJC_EXCEPTIONS/
     13        END_BLOCK_OBJC_EXCEPTIONS.
     14
     15        * platform/mac/ScrollbarThemeMac.mm:
     16        (WebCore::ScrollbarThemeMac::scrollbarThickness):
     17        (WebCore::ScrollbarThemeMac::updateScrollbarOverlayStyle):
     18        (WebCore::ScrollbarThemeMac::minimumThumbLength):
     19        (WebCore::ScrollbarThemeMac::updateEnabledState):
     20        (WebCore::ScrollbarThemeMac::setPaintCharacteristicsForScrollbar):
     21        (WebCore::scrollbarPainterPaint):
     22
    1232013-12-09  Ryosuke Niwa  <rniwa@webkit.org>
    224
  • trunk/Source/WebCore/platform/mac/ScrollbarThemeMac.mm

    r159027 r160335  
    2727#include "ScrollbarThemeMac.h"
    2828
     29#include "BlockExceptions.h"
    2930#include "ColorMac.h"
    3031#include "ImageBuffer.h"
     
    222223int ScrollbarThemeMac::scrollbarThickness(ScrollbarControlSize controlSize)
    223224{
     225    BEGIN_BLOCK_OBJC_EXCEPTIONS;
    224226    ScrollbarPainter scrollbarPainter = [NSClassFromString(@"NSScrollerImp") scrollerImpWithStyle:recommendedScrollerStyle() controlSize:controlSize horizontal:NO replacingScrollerImp:nil];
    225227    if (supportsExpandedScrollbars())
    226228        [scrollbarPainter setExpanded:YES];
    227229    return [scrollbarPainter trackBoxWidth];
     230    END_BLOCK_OBJC_EXCEPTIONS;
    228231}
    229232
     
    240243void ScrollbarThemeMac::updateScrollbarOverlayStyle(ScrollbarThemeClient* scrollbar)
    241244{
     245    BEGIN_BLOCK_OBJC_EXCEPTIONS;
    242246    ScrollbarPainter painter = painterForScrollbar(scrollbar);
    243247    switch (scrollbar->scrollbarOverlayStyle()) {
     
    252256        break;
    253257    }
     258    END_BLOCK_OBJC_EXCEPTIONS;
    254259}
    255260
     
    421426int ScrollbarThemeMac::minimumThumbLength(ScrollbarThemeClient* scrollbar)
    422427{
     428    BEGIN_BLOCK_OBJC_EXCEPTIONS;
    423429    return [scrollbarMap()->get(scrollbar) knobMinLength];
     430    END_BLOCK_OBJC_EXCEPTIONS;
    424431}
    425432
     
    458465void ScrollbarThemeMac::updateEnabledState(ScrollbarThemeClient* scrollbar)
    459466{
     467    BEGIN_BLOCK_OBJC_EXCEPTIONS;
    460468    [scrollbarMap()->get(scrollbar) setEnabled:scrollbar->enabled()];
     469    END_BLOCK_OBJC_EXCEPTIONS;
    461470}
    462471
    463472void ScrollbarThemeMac::setPaintCharacteristicsForScrollbar(ScrollbarThemeClient* scrollbar)
    464473{
     474    BEGIN_BLOCK_OBJC_EXCEPTIONS;
    465475    ScrollbarPainter painter = painterForScrollbar(scrollbar);
    466476
     
    468478    float overhang;
    469479    ScrollableArea::computeScrollbarValueAndOverhang(scrollbar->currentPos(), scrollbar->totalSize(), scrollbar->visibleSize(), value, overhang);
    470     float proportion = (static_cast<CGFloat>(scrollbar->visibleSize()) - overhang) / scrollbar->totalSize();
     480    float proportion = scrollbar->totalSize() > 0 ? (static_cast<CGFloat>(scrollbar->visibleSize()) - overhang) / scrollbar->totalSize() : 1;
    471481
    472482    [painter setEnabled:scrollbar->enabled()];
     
    474484    [painter setDoubleValue:value];
    475485    [painter setKnobProportion:proportion];
     486    END_BLOCK_OBJC_EXCEPTIONS;
    476487}
    477488
    478489static void scrollbarPainterPaint(ScrollbarPainter scrollbarPainter, bool enabled)
    479490{
     491    BEGIN_BLOCK_OBJC_EXCEPTIONS;
    480492    // Use rectForPart: here; it will take the expansion transition progress into account.
    481493    NSRect trackRect = [scrollbarPainter rectForPart:NSScrollerKnobSlot];
     
    486498    if (enabled)
    487499        [scrollbarPainter drawKnob];
     500    END_BLOCK_OBJC_EXCEPTIONS;
    488501}
    489502
Note: See TracChangeset for help on using the changeset viewer.