Changeset 239355 in webkit


Ignore:
Timestamp:
Dec 18, 2018 2:24:33 PM (5 years ago)
Author:
mark.lam@apple.com
Message:

JSON.stringify() should throw OOM on StringBuilder overflows.
https://bugs.webkit.org/show_bug.cgi?id=192822
<rdar://problem/46670577>

Reviewed by Saam Barati.

JSTests:

  • stress/json-stringify-string-builder-overflow.js: Added.

Source/JavaScriptCore:

  • runtime/JSONObject.cpp:

(JSC::Stringifier::stringify):
(JSC::Stringifier::appendStringifiedValue):
(JSC::Stringifier::Holder::appendNextProperty):

Location:
trunk
Files:
1 added
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/JSTests/ChangeLog

    r239354 r239355  
     12018-12-18  Mark Lam  <mark.lam@apple.com>
     2
     3        JSON.stringify() should throw OOM on StringBuilder overflows.
     4        https://bugs.webkit.org/show_bug.cgi?id=192822
     5        <rdar://problem/46670577>
     6
     7        Reviewed by Saam Barati.
     8
     9        * stress/json-stringify-string-builder-overflow.js: Added.
     10
    1112018-12-18  Ross Kirsling  <ross.kirsling@sony.com>
    212
  • trunk/Source/JavaScriptCore/ChangeLog

    r239354 r239355  
     12018-12-18  Mark Lam  <mark.lam@apple.com>
     2
     3        JSON.stringify() should throw OOM on StringBuilder overflows.
     4        https://bugs.webkit.org/show_bug.cgi?id=192822
     5        <rdar://problem/46670577>
     6
     7        Reviewed by Saam Barati.
     8
     9        * runtime/JSONObject.cpp:
     10        (JSC::Stringifier::stringify):
     11        (JSC::Stringifier::appendStringifiedValue):
     12        (JSC::Stringifier::Holder::appendNextProperty):
     13
    1142018-12-18  Ross Kirsling  <ross.kirsling@sony.com>
    215
  • trunk/Source/JavaScriptCore/runtime/JSONObject.cpp

    r237577 r239355  
    270270    if (isCallableReplacer()) {
    271271        object = constructEmptyObject(m_exec);
    272         RETURN_IF_EXCEPTION(scope, jsNull());
     272        RETURN_IF_EXCEPTION(scope, jsUndefined());
    273273        object->putDirect(vm, vm.propertyNames->emptyIdentifier, value);
    274274    }
     
    277277    Holder root(Holder::RootHolder, object);
    278278    auto stringifyResult = appendStringifiedValue(result, value, root, emptyPropertyName);
    279     EXCEPTION_ASSERT(!scope.exception() || (stringifyResult != StringifySucceeded));
     279    RETURN_IF_EXCEPTION(scope, jsUndefined());
     280    if (UNLIKELY(result.hasOverflowed())) {
     281        throwOutOfMemoryError(m_exec, scope);
     282        return jsUndefined();
     283    }
    280284    if (UNLIKELY(stringifyResult != StringifySucceeded))
    281285        return jsUndefined();
    282 
    283286    RELEASE_AND_RETURN(scope, jsString(m_exec, result.toString()));
    284287}
     
    360363        RETURN_IF_EXCEPTION(scope, StringifyFailed);
    361364        builder.appendQuotedJSONString(string);
    362         if (UNLIKELY(builder.hasOverflowed())) {
    363             throwOutOfMemoryError(m_exec, scope);
    364             return StringifyFailed;
    365         }
    366365        return StringifySucceeded;
    367366    }
     
    392391    }
    393392
     393    if (UNLIKELY(builder.hasOverflowed()))
     394        return StringifyFailed;
     395
    394396    // Handle cycle detection, and put the holder on the stack.
    395397    for (unsigned i = 0; i < m_holderStack.size(); i++) {
     
    411413            RETURN_IF_EXCEPTION(scope, StringifyFailed);
    412414        RETURN_IF_EXCEPTION(scope, StringifyFailed);
     415        if (UNLIKELY(builder.hasOverflowed()))
     416            return StringifyFailed;
    413417        m_holderStack.removeLast();
    414418        m_objectStack.removeLast();
     
    494498        stringifier.indent();
    495499    }
     500    if (UNLIKELY(builder.hasOverflowed()))
     501        return false;
    496502
    497503    // Last time through, finish up and return false.
Note: See TracChangeset for help on using the changeset viewer.