Ignore:
Timestamp:
Oct 26, 2017, 3:36:04 PM (8 years ago)
Author:
[email protected]
Message:

JSRopeString::RopeBuilder::append() should check for overflows.
https://bugs.webkit.org/show_bug.cgi?id=178385
<rdar://problem/35027468>

Reviewed by Saam Barati.

JSTests:

  • stress/regress-178385.js: Added.

Source/JavaScriptCore:

  1. Made RopeString check for overflow like the Checked class does.
  2. Added a missing overflow check in objectProtoFuncToString().
  • runtime/JSString.cpp:

(JSC::JSRopeString::RopeBuilder<RecordOverflow>::expand):
(JSC::JSRopeString::RopeBuilder::expand): Deleted.

  • runtime/JSString.h:
  • runtime/ObjectPrototype.cpp:

(JSC::objectProtoFuncToString):

  • runtime/Operations.h:

(JSC::jsStringFromRegisterArray):
(JSC::jsStringFromArguments):

Source/WTF:

  • wtf/CheckedArithmetic.h:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/runtime/JSString.h

    r222473 r224055  
    3131#include "ThrowScope.h"
    3232#include <array>
     33#include <wtf/CheckedArithmetic.h>
    3334#include <wtf/text/StringView.h>
    3435
     
    243244
    244245public:
    245     class RopeBuilder {
     246    template <class OverflowHandler = CrashOnOverflow>
     247    class RopeBuilder : public OverflowHandler {
    246248    public:
    247249        RopeBuilder(VM& vm)
     
    254256        bool append(JSString* jsString)
    255257        {
     258            if (UNLIKELY(this->hasOverflowed()))
     259                return false;
    256260            if (m_index == JSRopeString::s_maxInternalRopeLength)
    257261                expand();
    258262            if (static_cast<int32_t>(m_jsString->length() + jsString->length()) < 0) {
    259                 m_jsString = nullptr;
     263                this->overflowed();
    260264                return false;
    261265            }
     
    266270        JSRopeString* release()
    267271        {
    268             RELEASE_ASSERT(m_jsString);
     272            RELEASE_ASSERT(!this->hasOverflowed());
    269273            JSRopeString* tmp = m_jsString;
    270             m_jsString = 0;
     274            m_jsString = nullptr;
    271275            return tmp;
    272276        }
    273277
    274         unsigned length() const { return m_jsString->length(); }
     278        unsigned length() const
     279        {
     280            ASSERT(!this->hasOverflowed());
     281            return m_jsString->length();
     282        }
    275283
    276284    private:
Note: See TracChangeset for help on using the changeset viewer.