Changeset 242910 in webkit


Ignore:
Timestamp:
Mar 13, 2019 2:42:17 PM (5 years ago)
Author:
dinfuehr@igalia.com
Message:

String overflow when using StringBuilder in JSC::createError
https://bugs.webkit.org/show_bug.cgi?id=194957

Reviewed by Mark Lam.

JSTests:

Add test string-overflow-createError-bulder.js that overflows
StringBuilder in notAFunctionSourceAppender. The second new test
string-overflow-createError-fit.js has an error message that doesn't
overflow, it still failed since the String's capacity can't be doubled.
Run test string-overflow-createError.js only in the default
configuration to reduce memory consumption when running the test
in all configurations on multiple CPUs in parallel.

  • stress/string-overflow-createError-builder.js: Copied from JSTests/stress/string-overflow-createError.js.

(catch):

  • stress/string-overflow-createError-fit.js: Copied from JSTests/stress/string-overflow-createError.js.

(catch):

  • stress/string-overflow-createError.js:

Source/JavaScriptCore:

StringBuilder in notAFunctionSourceAppender didn't check
for overflows but just failed.

  • runtime/ExceptionHelpers.cpp:

(JSC::notAFunctionSourceAppender):

Source/WTF:

When calculating the new capacity of a StringBuilder object,
use a limit of MaxLength instead of MaxLength+1. Allocating
a string of size MaxLength+1 always fails. This means that expanding
a StringBuilder only worked when the newly doubled capacity is less or
equal to MaxLength.

  • wtf/text/StringBuilder.cpp:
Location:
trunk
Files:
2 added
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/JSTests/ChangeLog

    r242841 r242910  
     12019-03-13  Dominik Infuehr  <dinfuehr@igalia.com>
     2
     3        String overflow when using StringBuilder in JSC::createError
     4        https://bugs.webkit.org/show_bug.cgi?id=194957
     5
     6        Reviewed by Mark Lam.
     7
     8        Add test string-overflow-createError-bulder.js that overflows
     9        StringBuilder in notAFunctionSourceAppender. The second new test
     10        string-overflow-createError-fit.js has an error message that doesn't
     11        overflow, it still failed since the String's capacity can't be doubled.
     12        Run test string-overflow-createError.js only in the default
     13        configuration to reduce memory consumption when running the test
     14        in all configurations on multiple CPUs in parallel.
     15
     16        * stress/string-overflow-createError-builder.js: Copied from JSTests/stress/string-overflow-createError.js.
     17        (catch):
     18        * stress/string-overflow-createError-fit.js: Copied from JSTests/stress/string-overflow-createError.js.
     19        (catch):
     20        * stress/string-overflow-createError.js:
     21
    1222019-03-12  Yusuke Suzuki  <ysuzuki@apple.com>
    223
  • trunk/JSTests/stress/string-overflow-createError.js

    r239560 r242910  
    11//@ skip if $memoryLimited
     2//@ runDefault
    23var exception;
    34try {
     
    910}
    1011
     12// Creating the error message for the TypeError overflows
     13// the string and therefore an out-of-memory error is thrown.
    1114if (exception != "Error: Out of memory")
    1215    throw "FAILED";
  • trunk/Source/JavaScriptCore/ChangeLog

    r242902 r242910  
     12019-03-13  Dominik Infuehr  <dinfuehr@igalia.com>
     2
     3        String overflow when using StringBuilder in JSC::createError
     4        https://bugs.webkit.org/show_bug.cgi?id=194957
     5
     6        Reviewed by Mark Lam.
     7
     8        StringBuilder in notAFunctionSourceAppender didn't check
     9        for overflows but just failed.
     10
     11        * runtime/ExceptionHelpers.cpp:
     12        (JSC::notAFunctionSourceAppender):
     13
    1142019-03-11  Yusuke Suzuki  <ysuzuki@apple.com>
    215
  • trunk/Source/JavaScriptCore/runtime/ExceptionHelpers.cpp

    r242596 r242910  
    194194    if (!base)
    195195        return defaultApproximateSourceError(originalMessage, sourceText);
    196     StringBuilder builder;
     196    StringBuilder builder(StringBuilder::OverflowHandler::RecordOverflow);
    197197    builder.append(base);
    198198    builder.appendLiteral(" is not a function. (In '");
     
    210210    builder.append(')');
    211211
     212    if (builder.hasOverflowed())
     213        return makeString("object is not a function."_s);
     214
    212215    return builder.toString();
    213216}
  • trunk/Source/WTF/ChangeLog

    r242909 r242910  
     12019-03-13  Dominik Infuehr  <dinfuehr@igalia.com>
     2
     3        String overflow when using StringBuilder in JSC::createError
     4        https://bugs.webkit.org/show_bug.cgi?id=194957
     5
     6        Reviewed by Mark Lam.
     7
     8        When calculating the new capacity of a StringBuilder object,
     9        use a limit of MaxLength instead of MaxLength+1.  Allocating
     10        a string of size MaxLength+1 always fails. This means that expanding
     11        a StringBuilder only worked when the newly doubled capacity is less or
     12        equal to MaxLength.
     13
     14        * wtf/text/StringBuilder.cpp:
     15
    1162019-03-13  Chris Dumez  <cdumez@apple.com>
    217
  • trunk/Source/WTF/wtf/text/StringBuilder.cpp

    r242360 r242910  
    3535namespace WTF {
    3636
    37 static constexpr unsigned maxCapacity = String::MaxLength + 1;
     37static constexpr unsigned maxCapacity = String::MaxLength;
    3838
    3939static unsigned expandedCapacity(unsigned capacity, unsigned requiredLength)
Note: See TracChangeset for help on using the changeset viewer.