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

Changeset 259788 in webkit


Ignore:
Timestamp:
Apr 9, 2020, 3:52:52 AM (6 years ago)
Author:
ddkilzer@apple.com
Message:

Follow-up: WTF::Persistence::VectorCoder and IPC::VectorArgumentCoder should do bounds checking without crashing
<https://webkit.org/b/210227>
<rdar://problem/60832243>

Reviewed by Alex Christensen.

Source/WebKit:

  • Platform/IPC/ArgumentCoders.h:
  • Add missing call to decoder.markInvalid() if decoding of decodedSize fails.
  • Replace safeCast<size_t> with isInBounds<size_t> so that we don't crash if decodedSize is too big. Instead we fail decoding by marking the decoder invalid and returning early.
  • Revert checked arithemtic for multiplication since bufferIsLargeEnoughToContain<T(size) already did this check for us.

Source/WTF:

  • wtf/persistence/PersistentCoders.h:

(WTF::Persistence::VectorCoder::decode):

  • Replace safeCast<size_t> with isInBounds<size_t> so that we don't crash if decodedSize is too big. Instead we fail decoding by returning early.
  • Revert checked arithemtic for multiplication since bufferIsLargeEnoughToContain<T(size) already did this check for us.
Location:
trunk/Source
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WTF/ChangeLog

    r259786 r259788  
     12020-04-09  David Kilzer  <ddkilzer@apple.com>
     2
     3        Follow-up: WTF::Persistence::VectorCoder and IPC::VectorArgumentCoder should do bounds checking without crashing
     4        <https://webkit.org/b/210227>
     5        <rdar://problem/60832243>
     6
     7        Reviewed by Alex Christensen.
     8
     9        * wtf/persistence/PersistentCoders.h:
     10        (WTF::Persistence::VectorCoder::decode):
     11        - Replace safeCast<size_t> with isInBounds<size_t> so that we
     12          don't crash if `decodedSize` is too big.  Instead we fail
     13          decoding by returning early.
     14        - Revert checked arithemtic for multiplication since
     15          bufferIsLargeEnoughToContain<T(size) already did this check
     16          for us.
     17
    1182020-04-09  Mark Lam  <mark.lam@apple.com>
    219
  • trunk/Source/WTF/wtf/persistence/PersistentCoders.h

    r259780 r259788  
    161161            return false;
    162162
    163         auto size = safeCast<size_t>(decodedSize);
     163        if (!isInBounds<size_t>(decodedSize))
     164            return false;
     165
     166        auto size = static_cast<size_t>(decodedSize);
    164167
    165168        // Since we know the total size of the elements, we can allocate the vector in
     
    172175        temp.grow(size);
    173176
    174         Checked<size_t> checkedSize(size);
    175         decoder.decodeFixedLengthData(reinterpret_cast<uint8_t*>(temp.data()), (checkedSize * sizeof(T)).unsafeGet());
     177        decoder.decodeFixedLengthData(reinterpret_cast<uint8_t*>(temp.data()), size * sizeof(T));
    176178
    177179        vector.swap(temp);
  • trunk/Source/WebKit/ChangeLog

    r259780 r259788  
     12020-04-09  David Kilzer  <ddkilzer@apple.com>
     2
     3        Follow-up: WTF::Persistence::VectorCoder and IPC::VectorArgumentCoder should do bounds checking without crashing
     4        <https://webkit.org/b/210227>
     5        <rdar://problem/60832243>
     6
     7        Reviewed by Alex Christensen.
     8
     9        * Platform/IPC/ArgumentCoders.h:
     10        - Add missing call to decoder.markInvalid() if decoding of
     11          `decodedSize` fails.
     12        - Replace safeCast<size_t> with isInBounds<size_t> so that we
     13          don't crash if `decodedSize` is too big.  Instead we fail
     14          decoding by marking the decoder invalid and returning early.
     15        - Revert checked arithemtic for multiplication since
     16          bufferIsLargeEnoughToContain<T(size) already did this check
     17          for us.
     18
    1192020-04-08  David Kilzer  <ddkilzer@apple.com>
    220
  • trunk/Source/WebKit/Platform/IPC/ArgumentCoders.h

    r259780 r259788  
    368368    {
    369369        uint64_t decodedSize;
    370         if (!decoder.decode(decodedSize))
    371             return false;
    372 
    373         auto size = safeCast<size_t>(decodedSize);
     370        if (!decoder.decode(decodedSize)) {
     371            decoder.markInvalid();
     372            return false;
     373        }
     374
     375        if (!WTF::isInBounds<size_t>(decodedSize)) {
     376            decoder.markInvalid();
     377            return false;
     378        }
     379
     380        auto size = static_cast<size_t>(decodedSize);
    374381
    375382        // Since we know the total size of the elements, we can allocate the vector in
     
    384391        temp.grow(size);
    385392
    386         Checked<size_t> checkedSize(size);
    387         if (!decoder.decodeFixedLengthData(reinterpret_cast<uint8_t*>(temp.data()), (checkedSize * sizeof(T)).unsafeGet(), alignof(T))) {
     393        if (!decoder.decodeFixedLengthData(reinterpret_cast<uint8_t*>(temp.data()), size * sizeof(T), alignof(T))) {
    388394            decoder.markInvalid();
    389395            return false;
     
    397403    {
    398404        uint64_t decodedSize;
    399         if (!decoder.decode(decodedSize))
    400             return WTF::nullopt;
    401 
    402         auto size = safeCast<size_t>(decodedSize);
     405        if (!decoder.decode(decodedSize)) {
     406            decoder.markInvalid();
     407            return WTF::nullopt;
     408        }
     409
     410        if (!WTF::isInBounds<size_t>(decodedSize)) {
     411            decoder.markInvalid();
     412            return WTF::nullopt;
     413        }
     414
     415        auto size = static_cast<size_t>(decodedSize);
    403416
    404417        // Since we know the total size of the elements, we can allocate the vector in
     
    413426        vector.grow(size);
    414427
    415         Checked<size_t> checkedSize(size);
    416         if (!decoder.decodeFixedLengthData(reinterpret_cast<uint8_t*>(vector.data()), (checkedSize * sizeof(T)).unsafeGet(), alignof(T))) {
     428        if (!decoder.decodeFixedLengthData(reinterpret_cast<uint8_t*>(vector.data()), size * sizeof(T), alignof(T))) {
    417429            decoder.markInvalid();
    418430            return WTF::nullopt;
Note: See TracChangeset for help on using the changeset viewer.