Changeset 20357 in webkit


Ignore:
Timestamp:
Mar 20, 2007 10:39:57 PM (17 years ago)
Author:
beidson
Message:

Reviewed by Anders

<rdar://problem/5073391> and http://bugs.webkit.org/show_bug.cgi?id=13137

Crash in IconDatabase when private browsing is enabled.

The problem was caused by http://trac.webkit.org/projects/webkit/changeset/20182
which changed many uses of char[] and Vector<char> to SharedBuffer. The patch
tended to literally replace a Vector<char> with RefPtr<SharedBuffers> but forgot
to enforce the concept that Vector<char>'s always exist, whereas RefPtr<SharedBuffers>
can be null. This led to derefs.

I took the opportunity to rework the iconDB functions to live in a SharedBuffer
world, as that didn't exist when they were originally written - now they just return
SharedBuffers instead of taking a Vector<char>& as a parameter

  • loader/icon/IconDatabase.cpp: (WebCore::IconDatabase::imageDataForIconURL): Return a SharedBuffer (WebCore::IconDatabase::iconForPageURL): Null check the SharedBuffer before asking it if it's empty (WebCore::IconDatabase::imageDataForIconURLQuery): Return a new SharedBuffer
  • loader/icon/IconDatabase.h: Return SharedBuffer's instead of taking Vector<char>&'s
Location:
trunk/WebCore
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebCore/ChangeLog

    r20355 r20357  
     12007-03-20  Brady Eidson  <beidson@apple.com>
     2
     3        Reviewed by Anders
     4
     5        <rdar://problem/5073391> and http://bugs.webkit.org/show_bug.cgi?id=13137
     6
     7        Crash in IconDatabase when private browsing is enabled.
     8
     9        The problem was caused by http://trac.webkit.org/projects/webkit/changeset/20182
     10        which changed many uses of char[] and Vector<char> to SharedBuffer.  The patch
     11        tended to literally replace a Vector<char> with RefPtr<SharedBuffers> but forgot
     12        to enforce the concept that Vector<char>'s always exist, whereas RefPtr<SharedBuffers>
     13        can be null.  This led to derefs.
     14
     15        I took the opportunity to rework the iconDB functions to live in a SharedBuffer
     16        world, as that didn't exist when they were originally written - now they just return
     17        SharedBuffers instead of taking a Vector<char>& as a parameter
     18
     19        * loader/icon/IconDatabase.cpp:
     20        (WebCore::IconDatabase::imageDataForIconURL): Return a SharedBuffer
     21        (WebCore::IconDatabase::iconForPageURL): Null check the SharedBuffer before asking
     22          it if it's empty
     23        (WebCore::IconDatabase::imageDataForIconURLQuery): Return a new SharedBuffer
     24
     25        * loader/icon/IconDatabase.h: Return SharedBuffer's instead of taking Vector<char>&'s
     26
    1272007-03-20  Adam Roben  <aroben@apple.com>
    228
  • trunk/WebCore/loader/icon/IconDatabase.cpp

    r20243 r20357  
    325325}   
    326326
    327 void IconDatabase::imageDataForIconURL(const String& iconURL, PassRefPtr<SharedBuffer> result)
     327PassRefPtr<SharedBuffer> IconDatabase::imageDataForIconURL(const String& iconURL)
    328328{     
    329329    // If private browsing is enabled, we'll check there first as the most up-to-date data for an icon will be there
    330330    if (m_privateBrowsingEnabled) {   
    331         imageDataForIconURLQuery(m_privateBrowsingDB, iconURL, result);
    332         if (!result->isEmpty())
    333             return;
     331        RefPtr<SharedBuffer> result = imageDataForIconURLQuery(m_privateBrowsingDB, iconURL);
     332        if (result && !result->isEmpty())
     333            return result.release();
    334334    }
    335335   
    336336    // It wasn't found there, so lets check the main tables
    337     imageDataForIconURLQuery(m_mainDB, iconURL, result);
     337    return imageDataForIconURLQuery(m_mainDB, iconURL);
    338338}
    339339
     
    375375    // we'll read in that image data now
    376376    if (icon->imageDataStatus() == ImageDataStatusUnknown) {
    377         RefPtr<SharedBuffer> data = new SharedBuffer();
    378         imageDataForIconURL(iconURL, data.get());
     377        RefPtr<SharedBuffer> data = imageDataForIconURL(iconURL);
    379378        icon->setImageData(data.get());
    380379    }
     
    954953}
    955954
    956 void IconDatabase::imageDataForIconURLQuery(SQLDatabase& db, const String& iconURL, PassRefPtr<SharedBuffer> imageData)
    957 {
     955PassRefPtr<SharedBuffer> IconDatabase::imageDataForIconURLQuery(SQLDatabase& db, const String& iconURL)
     956{
     957    RefPtr<SharedBuffer> imageData;
     958   
    958959    readySQLStatement(m_imageDataForIconURLStatement, db, "SELECT Icon.data FROM Icon WHERE Icon.url = (?);");
    959960    m_imageDataForIconURLStatement->bindText16(1, iconURL, false);
    960961   
    961962    int result = m_imageDataForIconURLStatement->step();
    962     imageData->clear();
    963963    if (result == SQLResultRow) {
    964964        Vector<char> data;
    965965        m_imageDataForIconURLStatement->getColumnBlobAsVector(0, data);
     966        imageData = new SharedBuffer;
    966967        imageData->append(data.data(), data.size());
    967968    } else if (result != SQLResultDone)
     
    969970
    970971    m_imageDataForIconURLStatement->reset();
     972   
     973    return imageData.release();
    971974}
    972975
  • trunk/WebCore/loader/icon/IconDatabase.h

    r20182 r20357  
    123123   
    124124    // Returns the image data for the given IconURL, checking both databases if necessary
    125     void imageDataForIconURL(const String& iconURL, PassRefPtr<SharedBuffer> result);
     125    PassRefPtr<SharedBuffer> imageDataForIconURL(const String& iconURL);
    126126   
    127127    // Retains an iconURL, bringing it back from the brink if it was pending deletion
     
    163163   
    164164    // Query - Returns the image data from the given database for the given IconURL
    165     void imageDataForIconURLQuery(SQLDatabase& db, const String& iconURL, PassRefPtr<SharedBuffer> result);
     165    PassRefPtr<SharedBuffer> imageDataForIconURLQuery(SQLDatabase& db, const String& iconURL);
    166166    SQLStatement* m_imageDataForIconURLStatement;
    167167
Note: See TracChangeset for help on using the changeset viewer.