Skip to content
Permalink
Browse files
Crash on sfgate.com because mismatching link preload types
https://bugs.webkit.org/show_bug.cgi?id=182483
<rdar://problem/37065331>

Reviewed by Daniel Bates.

Source/WebCore:

Preloading the same URL with different 'as' types causes some confusion.

Test: http/tests/preload/link-preload-type-mismatch.html

* loader/LinkLoader.cpp:
(WebCore::createLinkPreloadResourceClient):

    Ensure we use the actual resource type when creating the client.

(WebCore::LinkLoader::preloadIfNeeded):

    Don't construct client if the types don't match. This can happen if there is an existing
    preload for the same resource with different type.

LayoutTests:

* http/tests/preload/link-preload-type-mismatch-expected.txt: Added.
* http/tests/preload/link-preload-type-mismatch.html: Added.


Canonical link: https://commits.webkit.org/198277@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@228096 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
anttijk committed Feb 5, 2018
1 parent 62bb173 commit ef07bacaee7029772723c49a406fca21dacc195e
@@ -1,3 +1,14 @@
2018-02-05 Antti Koivisto <antti@apple.com>

Crash on sfgate.com because mismatching link preload types
https://bugs.webkit.org/show_bug.cgi?id=182483
<rdar://problem/37065331>

Reviewed by Daniel Bates.

* http/tests/preload/link-preload-type-mismatch-expected.txt: Added.
* http/tests/preload/link-preload-type-mismatch.html: Added.

2018-02-05 Manuel Rego Casasnovas <rego@igalia.com>

[css-grid] Rename gutter properties to remove "grid-" prefix
@@ -0,0 +1 @@
Test mismatching preload types. The test passes if it doesn't crash or assert.
@@ -0,0 +1,16 @@
<!DOCTYPE html>
<script>
if (window.testRunner) {
testRunner.dumpAsText()
testRunner.waitUntilDone();
window.addEventListener("load", function() {
testRunner.notifyDone();
});
}
</script>
<link rel=preload href="../resources/dummy.js" as=fetch>
<link rel=preload href="../resources/dummy.js" as=script>
<body>
Test mismatching preload types. The test passes if it doesn't crash or assert.
<script src="../resources/dummy.js"></script>
</body>
@@ -1,3 +1,25 @@
2018-02-05 Antti Koivisto <antti@apple.com>

Crash on sfgate.com because mismatching link preload types
https://bugs.webkit.org/show_bug.cgi?id=182483
<rdar://problem/37065331>

Reviewed by Daniel Bates.

Preloading the same URL with different 'as' types causes some confusion.

Test: http/tests/preload/link-preload-type-mismatch.html

* loader/LinkLoader.cpp:
(WebCore::createLinkPreloadResourceClient):

Ensure we use the actual resource type when creating the client.

(WebCore::LinkLoader::preloadIfNeeded):

Don't construct client if the types don't match. This can happen if there is an existing
preload for the same resource with different type.

2018-02-05 Manuel Rego Casasnovas <rego@igalia.com>

[css-grid] Rename gutter properties to remove "grid-" prefix
@@ -135,9 +135,9 @@ std::optional<CachedResource::Type> LinkLoader::resourceTypeFromAsAttribute(cons
return std::nullopt;
}

static std::unique_ptr<LinkPreloadResourceClient> createLinkPreloadResourceClient(CachedResource& resource, LinkLoader& loader, CachedResource::Type type)
static std::unique_ptr<LinkPreloadResourceClient> createLinkPreloadResourceClient(CachedResource& resource, LinkLoader& loader)
{
switch (type) {
switch (resource.type()) {
case CachedResource::ImageResource:
return LinkPreloadImageResourceClient::create(loader, static_cast<CachedImage&>(resource));
case CachedResource::Script:
@@ -239,8 +239,11 @@ std::unique_ptr<LinkPreloadResourceClient> LinkLoader::preloadIfNeeded(const Lin
linkRequest.setAsPotentiallyCrossOrigin(crossOriginMode, document);
auto cachedLinkResource = document.cachedResourceLoader().preload(type.value(), WTFMove(linkRequest)).value_or(nullptr);

if (cachedLinkResource && cachedLinkResource->type() != *type)
return nullptr;

if (cachedLinkResource && loader)
return createLinkPreloadResourceClient(*cachedLinkResource, *loader, type.value());
return createLinkPreloadResourceClient(*cachedLinkResource, *loader);
return nullptr;
}

0 comments on commit ef07bac

Please sign in to comment.