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

Changeset 181895 in webkit


Ignore:
Timestamp:
Mar 24, 2015, 9:50:55 AM (11 years ago)
Author:
Chris Dumez
Message:

[WK2] NetworkCache retrievals fail for entries with no body
https://bugs.webkit.org/show_bug.cgi?id=142979
<rdar://problem/20264100>

Reviewed by Antti Koivisto.

Source/WebKit2:

NetworkCache retrievals were failing for entries with no body because
decodeEntry() doesn't correctly handle this case. In particular, the
following check fails:
"metaData.bodyOffset + metaData.bodySize == fileData.size()".
This is because bodyOffset is pageSize-aligned.

As a result, the following resource on apple.com is stored in the cache
but we fail to reuse it and reload it from the network every time:
http://images.apple.com/home/styles/promos.css

This patch updates decodeEntry() to create a null Data object for the
body if bodySize is 0.

  • NetworkProcess/cache/NetworkCacheDataCocoa.mm:

(WebKit::NetworkCache::Data::data):
Do not attempt to initialize m_data if m_dispatchData is null as the
call to dispatch_data_create_map() would then crash. We now return
null in this case. This is needed as decodeStorageEntry() in
NetworkCache.cpp constructs a SharedBuffer from
storageEntry.body.data() and the body may be null.

  • NetworkProcess/cache/NetworkCacheStorage.cpp:

(WebKit::NetworkCache::decodeEntry):

LayoutTests:

Add network disk cache validation test for resources that have no body
(only headers).

  • http/tests/cache/disk-cache/disk-cache-validation-no-body-expected.txt: Added.
  • http/tests/cache/disk-cache/disk-cache-validation-no-body.html: Added.
  • http/tests/cache/disk-cache/resources/generate-response-no-body.cgi: Added.
Location:
trunk
Files:
3 added
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r181894 r181895  
     12015-03-24  Chris Dumez  <cdumez@apple.com>
     2
     3        [WK2] NetworkCache retrievals fail for entries with no body
     4        https://bugs.webkit.org/show_bug.cgi?id=142979
     5        <rdar://problem/20264100>
     6
     7        Reviewed by Antti Koivisto.
     8
     9        Add network disk cache validation test for resources that have no body
     10        (only headers).
     11
     12        * http/tests/cache/disk-cache/disk-cache-validation-no-body-expected.txt: Added.
     13        * http/tests/cache/disk-cache/disk-cache-validation-no-body.html: Added.
     14        * http/tests/cache/disk-cache/resources/generate-response-no-body.cgi: Added.
     15
    1162015-03-24  Chris Dumez  <cdumez@apple.com>
    217
  • trunk/Source/WebKit2/ChangeLog

    r181894 r181895  
     12015-03-24  Chris Dumez  <cdumez@apple.com>
     2
     3        [WK2] NetworkCache retrievals fail for entries with no body
     4        https://bugs.webkit.org/show_bug.cgi?id=142979
     5        <rdar://problem/20264100>
     6
     7        Reviewed by Antti Koivisto.
     8
     9        NetworkCache retrievals were failing for entries with no body because
     10        decodeEntry() doesn't correctly handle this case. In particular, the
     11        following check fails:
     12        "metaData.bodyOffset + metaData.bodySize == fileData.size()".
     13        This is because bodyOffset is pageSize-aligned.
     14
     15        As a result, the following resource on apple.com is stored in the cache
     16        but we fail to reuse it and reload it from the network every time:
     17        http://images.apple.com/home/styles/promos.css
     18
     19        This patch updates decodeEntry() to create a null Data object for the
     20        body if bodySize is 0.
     21
     22        * NetworkProcess/cache/NetworkCacheDataCocoa.mm:
     23        (WebKit::NetworkCache::Data::data):
     24        Do not attempt to initialize m_data if m_dispatchData is null as the
     25        call to dispatch_data_create_map() would then crash. We now return
     26        null in this case. This is needed as decodeStorageEntry() in
     27        NetworkCache.cpp constructs a SharedBuffer from
     28        storageEntry.body.data() and the body may be null.
     29
     30        * NetworkProcess/cache/NetworkCacheStorage.cpp:
     31        (WebKit::NetworkCache::decodeEntry):
     32
    1332015-03-24  Chris Dumez  <cdumez@apple.com>
    234
  • trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheDataCocoa.mm

    r181160 r181895  
    5050const uint8_t* Data::data() const
    5151{
    52     if (!m_data) {
     52    if (!m_data && m_dispatchData) {
    5353        const void* data;
    5454        size_t size;
  • trunk/Source/WebKit2/NetworkProcess/cache/NetworkCacheStorage.cpp

    r181816 r181895  
    213213    if (metaData.key != key)
    214214        return nullptr;
    215     if (metaData.bodyOffset + metaData.bodySize != fileData.size())
    216         return nullptr;
    217 
    218     auto bodyData = mapFile(fd, metaData.bodyOffset, metaData.bodySize);
    219     if (bodyData.isNull()) {
    220         LOG(NetworkCacheStorage, "(NetworkProcess) map failed");
    221         return nullptr;
    222     }
    223 
    224     if (metaData.bodyChecksum != hashData(bodyData)) {
    225         LOG(NetworkCacheStorage, "(NetworkProcess) data checksum mismatch");
    226         return nullptr;
     215
     216    Data bodyData;
     217    if (metaData.bodySize) {
     218        if (metaData.bodyOffset + metaData.bodySize != fileData.size())
     219            return nullptr;
     220
     221        bodyData = mapFile(fd, metaData.bodyOffset, metaData.bodySize);
     222        if (bodyData.isNull()) {
     223            LOG(NetworkCacheStorage, "(NetworkProcess) map failed");
     224            return nullptr;
     225        }
     226
     227        if (metaData.bodyChecksum != hashData(bodyData)) {
     228            LOG(NetworkCacheStorage, "(NetworkProcess) data checksum mismatch");
     229            return nullptr;
     230        }
    227231    }
    228232
Note: See TracChangeset for help on using the changeset viewer.