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

Changeset 259780 in webkit


Ignore:
Timestamp:
Apr 8, 2020, 9:33:27 PM (6 years ago)
Author:
ddkilzer@apple.com
Message:

WTF::Persistence::VectorCoder and IPC::VectorArgumentCoder should use checked arithmetic
<https://webkit.org/b/210227>
<rdar://problem/60832243>

Reviewed by Alex Christensen.

Source/WebKit:

  • Platform/IPC/ArgumentCoders.h:

(IPC::VectorArgumentCoder::decode):

  • Use safeCast<> to cast from uint64_t to size_t.
  • Use checked arithemtic for multiplication.

Source/WTF:

  • wtf/persistence/PersistentCoders.h:

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

  • Use checked arithemtic for multiplication.
Location:
trunk/Source
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WTF/ChangeLog

    r259773 r259780  
     12020-04-08  David Kilzer  <ddkilzer@apple.com>
     2
     3        WTF::Persistence::VectorCoder and IPC::VectorArgumentCoder should use checked arithmetic
     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        - Use checked arithemtic for multiplication.
     12
    1132020-04-08  Chris Dumez  <cdumez@apple.com>
    214
  • trunk/Source/WTF/wtf/persistence/PersistentCoders.h

    r248268 r259780  
    11/*
    2  * Copyright (C) 2010, 2014-2015 Apple Inc. All rights reserved.
     2 * Copyright (C) 2010-2020 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    2727
    2828#include <utility>
     29#include <wtf/CheckedArithmetic.h>
    2930#include <wtf/Forward.h>
    3031#include <wtf/HashMap.h>
     
    171172        temp.grow(size);
    172173
    173         decoder.decodeFixedLengthData(reinterpret_cast<uint8_t*>(temp.data()), size * sizeof(T));
     174        Checked<size_t> checkedSize(size);
     175        decoder.decodeFixedLengthData(reinterpret_cast<uint8_t*>(temp.data()), (checkedSize * sizeof(T)).unsafeGet());
    174176
    175177        vector.swap(temp);
  • trunk/Source/WebKit/ChangeLog

    r259779 r259780  
     12020-04-08  David Kilzer  <ddkilzer@apple.com>
     2
     3        WTF::Persistence::VectorCoder and IPC::VectorArgumentCoder should use checked arithmetic
     4        <https://webkit.org/b/210227>
     5        <rdar://problem/60832243>
     6
     7        Reviewed by Alex Christensen.
     8
     9        * Platform/IPC/ArgumentCoders.h:
     10        (IPC::VectorArgumentCoder::decode):
     11        - Use safeCast<> to cast from uint64_t to size_t.
     12        - Use checked arithemtic for multiplication.
     13
    1142020-04-08  Alexey Proskuryakov  <ap@apple.com>
    215
  • trunk/Source/WebKit/Platform/IPC/ArgumentCoders.h

    r258902 r259780  
    11/*
    2  * Copyright (C) 2010-2017 Apple Inc. All rights reserved.
     2 * Copyright (C) 2010-2020 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    3030#include <utility>
    3131#include <wtf/Box.h>
     32#include <wtf/CheckedArithmetic.h>
    3233#include <wtf/Forward.h>
    3334#include <wtf/MonotonicTime.h>
     
    366367    static bool decode(Decoder& decoder, Vector<T, inlineCapacity, OverflowHandler, minCapacity>& vector)
    367368    {
    368         uint64_t size;
    369         if (!decoder.decode(size))
    370             return false;
     369        uint64_t decodedSize;
     370        if (!decoder.decode(decodedSize))
     371            return false;
     372
     373        auto size = safeCast<size_t>(decodedSize);
    371374
    372375        // Since we know the total size of the elements, we can allocate the vector in
     
    381384        temp.grow(size);
    382385
    383         if (!decoder.decodeFixedLengthData(reinterpret_cast<uint8_t*>(temp.data()), size * sizeof(T), alignof(T))) {
     386        Checked<size_t> checkedSize(size);
     387        if (!decoder.decodeFixedLengthData(reinterpret_cast<uint8_t*>(temp.data()), (checkedSize * sizeof(T)).unsafeGet(), alignof(T))) {
    384388            decoder.markInvalid();
    385389            return false;
     
    392396    static Optional<Vector<T, inlineCapacity, OverflowHandler, minCapacity>> decode(Decoder& decoder)
    393397    {
    394         uint64_t size;
    395         if (!decoder.decode(size))
    396             return WTF::nullopt;
    397        
     398        uint64_t decodedSize;
     399        if (!decoder.decode(decodedSize))
     400            return WTF::nullopt;
     401
     402        auto size = safeCast<size_t>(decodedSize);
     403
    398404        // Since we know the total size of the elements, we can allocate the vector in
    399405        // one fell swoop. Before allocating we must however make sure that the decoder buffer
     
    407413        vector.grow(size);
    408414
    409         if (!decoder.decodeFixedLengthData(reinterpret_cast<uint8_t*>(vector.data()), size * sizeof(T), alignof(T))) {
     415        Checked<size_t> checkedSize(size);
     416        if (!decoder.decodeFixedLengthData(reinterpret_cast<uint8_t*>(vector.data()), (checkedSize * sizeof(T)).unsafeGet(), alignof(T))) {
    410417            decoder.markInvalid();
    411418            return WTF::nullopt;
Note: See TracChangeset for help on using the changeset viewer.