⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 235537 in webkit


Ignore:
Timestamp:
Aug 30, 2018, 9:27:44 PM (8 years ago)
Author:
Alan Bujtas
Message:

CounterMaps should hold a unique_ptr of CounterMap.
https://bugs.webkit.org/show_bug.cgi?id=189174
<rdar://problem/43686458>

Reviewed by Ryosuke Niwa.

Source/WebCore:

In certain cases calls to CounterMaps might lead to unexpected deletion of the CounterMap object.

Test: fast/css/counters/crash-when-cloning-body.html

  • rendering/RenderCounter.cpp:

(WebCore::makeCounterNode):
(WebCore::destroyCounterNodeWithoutMapRemoval):
(WebCore::RenderCounter::destroyCounterNodes):
(WebCore::RenderCounter::destroyCounterNode):
(WebCore::updateCounters):
(showCounterRendererTree):

LayoutTests:

  • fast/css/counters/crash-when-cloning-body-expected.txt: Added.
  • fast/css/counters/crash-when-cloning-body.html: Added.
Location:
trunk
Files:
2 added
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r235523 r235537  
     12018-08-30  Zalan Bujtas  <zalan@apple.com>
     2
     3        CounterMaps should hold a unique_ptr of CounterMap.
     4        https://bugs.webkit.org/show_bug.cgi?id=189174
     5        <rdar://problem/43686458>
     6
     7        Reviewed by Ryosuke Niwa.
     8
     9        * fast/css/counters/crash-when-cloning-body-expected.txt: Added.
     10        * fast/css/counters/crash-when-cloning-body.html: Added.
     11
    1122018-08-30  Truitt Savell  <tsavell@apple.com>
    213
  • trunk/Source/WebCore/ChangeLog

    r235536 r235537  
     12018-08-30  Zalan Bujtas  <zalan@apple.com>
     2
     3        CounterMaps should hold a unique_ptr of CounterMap.
     4        https://bugs.webkit.org/show_bug.cgi?id=189174
     5        <rdar://problem/43686458>
     6
     7        Reviewed by Ryosuke Niwa.
     8
     9        In certain cases calls to CounterMaps might lead to unexpected deletion of the CounterMap object.
     10
     11        Test: fast/css/counters/crash-when-cloning-body.html
     12
     13        * rendering/RenderCounter.cpp:
     14        (WebCore::makeCounterNode):
     15        (WebCore::destroyCounterNodeWithoutMapRemoval):
     16        (WebCore::RenderCounter::destroyCounterNodes):
     17        (WebCore::RenderCounter::destroyCounterNode):
     18        (WebCore::updateCounters):
     19        (showCounterRendererTree):
     20
    1212018-08-30  Ross Kirsling  <ross.kirsling@sony.com>
    222
  • trunk/Source/WebCore/rendering/RenderCounter.cpp

    r232178 r235537  
    4848
    4949using CounterMap = HashMap<AtomicString, Ref<CounterNode>>;
    50 using CounterMaps = HashMap<const RenderElement*, CounterMap>;
     50using CounterMaps = HashMap<const RenderElement*, std::unique_ptr<CounterMap>>;
    5151
    5252static CounterNode* makeCounterNode(RenderElement&, const AtomicString& identifier, bool alwaysCreateCounter);
     
    297297    if (renderer.hasCounterNodeMap()) {
    298298        ASSERT(counterMaps().contains(&renderer));
    299         if (auto* node = counterMaps().find(&renderer)->value.get(identifier))
     299        if (auto* node = counterMaps().find(&renderer)->value->get(identifier))
    300300            return node;
    301301    }
     
    313313        place.parent->insertAfter(newNode, place.previousSibling.get(), identifier);
    314314
    315     maps.add(&renderer, CounterMap { }).iterator->value.add(identifier, newNode.copyRef());
     315    maps.add(&renderer, std::make_unique<CounterMap>()).iterator->value->add(identifier, newNode.copyRef());
    316316    renderer.setHasCounterNodeMap(true);
    317317
     
    327327        if (!currentRenderer->hasCounterNodeMap())
    328328            continue;
    329         auto* currentCounter = maps.find(currentRenderer)->value.get(identifier);
     329        auto* currentCounter = maps.find(currentRenderer)->value->get(identifier);
    330330        if (!currentCounter)
    331331            continue;
     
    437437        previous = child->previousInPreOrder();
    438438        child->parent()->removeChild(*child);
    439         ASSERT(counterMaps().find(&child->owner())->value.get(identifier) == child);
    440         counterMaps().find(&child->owner())->value.remove(identifier);
     439        ASSERT(counterMaps().find(&child->owner())->value->get(identifier) == child);
     440        counterMaps().find(&child->owner())->value->remove(identifier);
    441441    }
    442442    if (auto* parent = node.parent())
     
    449449    auto& maps = counterMaps();
    450450    ASSERT(maps.contains(&owner));
    451     for (auto& keyValue : maps.take(&owner))
    452         destroyCounterNodeWithoutMapRemoval(keyValue.key, keyValue.value);
     451    auto counterMap = maps.take(&owner);
     452    for (auto& counterMapEntry : *counterMap)
     453        destroyCounterNodeWithoutMapRemoval(counterMapEntry.key, counterMapEntry.value);
    453454    owner.setHasCounterNodeMap(false);
    454455}
     
    459460    if (map == counterMaps().end())
    460461        return;
    461     auto node = map->value.take(identifier);
     462    auto node = map->value->take(identifier);
    462463    if (!node)
    463464        return;
     
    500501    }
    501502    ASSERT(counterMaps().contains(&renderer));
    502     auto& counterMap = counterMaps().find(&renderer)->value;
     503    auto* counterMap = counterMaps().find(&renderer)->value.get();
    503504    for (auto& key : directiveMap->keys()) {
    504         RefPtr<CounterNode> node = counterMap.get(key);
     505        RefPtr<CounterNode> node = counterMap->get(key);
    505506        if (!node) {
    506507            makeCounterNode(renderer, key, false);
     
    508509        }
    509510        auto place = findPlaceForCounter(renderer, key, node->hasResetType());
    510         if (node != counterMap.get(key))
     511        if (node != counterMap->get(key))
    511512            continue;
    512513        CounterNode* parent = node->parent();
     
    602603            current, current->node(), current->parent(), current->previousSibling(),
    603604            current->nextSibling(), downcast<WebCore::RenderElement>(*current).hasCounterNodeMap() ?
    604             counterName ? WebCore::counterMaps().find(downcast<WebCore::RenderElement>(current))->value.get(identifier) : (WebCore::CounterNode*)1 : (WebCore::CounterNode*)0);
     605            counterName ? WebCore::counterMaps().find(downcast<WebCore::RenderElement>(current))->value->get(identifier) : (WebCore::CounterNode*)1 : (WebCore::CounterNode*)0);
    605606    }
    606607    fflush(stderr);
Note: See TracChangeset for help on using the changeset viewer.