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

Changeset 281008 in webkit


Ignore:
Timestamp:
Aug 12, 2021, 10:45:45 PM (5 years ago)
Author:
Cameron McCormack
Message:

Fix bounds checks for WhitespaceCache string lengths
https://bugs.webkit.org/show_bug.cgi?id=229066
<rdar://81850871>

Reviewed by Simon Fraser.

When the whitespace string length is maximumWhitespaceStringLength,
we read from and write to one element past the end of m_codes and
m_indexes. Since we don't need to store codes and indexes for zero
length strings, subtract one from the index we use.

  • html/parser/HTMLConstructionSite.cpp:

(WebCore::WhitespaceCache::lookup):

  • html/parser/HTMLConstructionSite.h:
Location:
trunk/Source/WebCore
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r281001 r281008  
     12021-08-12  Cameron McCormack  <heycam@apple.com>
     2
     3        Fix bounds checks for WhitespaceCache string lengths
     4        https://bugs.webkit.org/show_bug.cgi?id=229066
     5        <rdar://81850871>
     6
     7        Reviewed by Simon Fraser.
     8
     9        When the whitespace string length is maximumWhitespaceStringLength,
     10        we read from and write to one element past the end of m_codes and
     11        m_indexes. Since we don't need to store codes and indexes for zero
     12        length strings, subtract one from the index we use.
     13
     14        * html/parser/HTMLConstructionSite.cpp:
     15        (WebCore::WhitespaceCache::lookup):
     16        * html/parser/HTMLConstructionSite.h:
     17
    1182021-08-12  David Kilzer  <ddkilzer@apple.com>
    219
  • trunk/Source/WebCore/html/parser/HTMLConstructionSite.cpp

    r280773 r281008  
    892892        return AtomString();
    893893
    894     if (m_codes[length] == code) {
    895         ASSERT(m_atoms[m_indexes[length]] == string);
    896         return m_atoms[m_indexes[length]];
     894    size_t lengthIndex = length - 1;
     895    if (m_codes[lengthIndex] == code) {
     896        ASSERT(m_atoms[m_indexes[lengthIndex]] == string);
     897        return m_atoms[m_indexes[lengthIndex]];
    897898    }
    898899
     
    900901        return AtomString(string);
    901902
    902     if (m_codes[length]) {
     903    if (m_codes[lengthIndex]) {
    903904        AtomString whitespaceAtom(string);
    904         m_codes[length] = code;
    905         m_atoms[m_indexes[length]] = whitespaceAtom;
     905        m_codes[lengthIndex] = code;
     906        m_atoms[m_indexes[lengthIndex]] = whitespaceAtom;
    906907        return whitespaceAtom;
    907908    }
    908909
    909910    AtomString whitespaceAtom(string);
    910     m_codes[length] = code;
    911     m_indexes[length] = m_atoms.size();
     911    m_codes[lengthIndex] = code;
     912    m_indexes[lengthIndex] = m_atoms.size();
    912913    m_atoms.append(whitespaceAtom);
    913914    return whitespaceAtom;
  • trunk/Source/WebCore/html/parser/HTMLConstructionSite.h

    r280772 r281008  
    239239
    240240    // Parallel arrays storing a 64 bit code and an index into m_atoms for the
    241     // most recently atomized whitespace-only string of a given length.
     241    // most recently atomized whitespace-only string of a given length. The
     242    // indices into these two arrays are the string length minus 1, so the code
     243    // for a whitespace-only string of length 2 is stored at m_codes[1], etc.
    242244    uint64_t m_codes[maximumCachedStringLength] { 0 };
    243245    uint8_t m_indexes[maximumCachedStringLength] { 0 };
Note: See TracChangeset for help on using the changeset viewer.