Changeset 54925 in webkit for trunk/JavaScriptCore/runtime


Ignore:
Timestamp:
Feb 17, 2010, 9:07:41 PM (15 years ago)
Author:
[email protected]
Message:

https://bugs.webkit.org/show_bug.cgi?id=35070
Addition of 2 strings of length 231 may result in a string of length 0.

Reviewed by Oliver Hunt.

Check for overflow when creating a new JSString as a result of an addition
or concatenation, throw an out of memory exception.

  • runtime/JSString.h:

(JSC::):

  • runtime/Operations.h:

(JSC::jsString):

Location:
trunk/JavaScriptCore/runtime
Files:
2 edited

Legend:

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

    r54843 r54925  
    105105            }
    106106
     107            unsigned length() { return m_rope->length(); }
     108
    107109        private:
    108110            unsigned m_index;
  • trunk/JavaScriptCore/runtime/Operations.h

    r54804 r54925  
    3838    ALWAYS_INLINE JSValue jsString(ExecState* exec, JSString* s1, JSString* s2)
    3939    {
    40         if (!s1->length())
     40        unsigned length1 = s1->length();
     41        if (!length1)
    4142            return s2;
    42         if (!s2->length())
     43        unsigned length2 = s2->length();
     44        if (!length2)
    4345            return s1;
     46        if ((length1 + length2) < length1)
     47            return throwOutOfMemoryError(exec);
    4448
    4549        unsigned fiberCount = s1->fiberCount() + s2->fiberCount();
     
    5963    ALWAYS_INLINE JSValue jsString(ExecState* exec, const UString& u1, JSString* s2)
    6064    {
     65        unsigned length1 = u1.size();
     66        if (!length1)
     67            return s2;
     68        unsigned length2 = s2->length();
     69        if (!length2)
     70            return jsString(exec, u1);
     71        if ((length1 + length2) < length1)
     72            return throwOutOfMemoryError(exec);
     73
    6174        unsigned fiberCount = 1 + s2->fiberCount();
    6275        JSGlobalData* globalData = &exec->globalData();
     
    7588    ALWAYS_INLINE JSValue jsString(ExecState* exec, JSString* s1, const UString& u2)
    7689    {
     90        unsigned length1 = s1->length();
     91        if (!length1)
     92            return jsString(exec, u2);
     93        unsigned length2 = u2.size();
     94        if (!length2)
     95            return s1;
     96        if ((length1 + length2) < length1)
     97            return throwOutOfMemoryError(exec);
     98
    7799        unsigned fiberCount = s1->fiberCount() + 1;
    78100        JSGlobalData* globalData = &exec->globalData();
     
    110132            return throwOutOfMemoryError(exec);
    111133
     134        unsigned length = 0;
     135        bool overflow = false;
     136
    112137        for (unsigned i = 0; i < count; ++i) {
    113138            JSValue v = strings[i].jsValue();
     
    116141            else
    117142                ropeBuilder.append(v.toString(exec));
    118         }
     143
     144            unsigned newLength = ropeBuilder.length();
     145            if (newLength < length)
     146                overflow = true;
     147            length = newLength;
     148        }
     149
     150        if (overflow)
     151            return throwOutOfMemoryError(exec);
    119152
    120153        return new (globalData) JSString(globalData, ropeBuilder.release());
     
    144177        else
    145178            ropeBuilder.append(thisValue.toString(exec));
     179
     180        unsigned length = 0;
     181        bool overflow = false;
     182
    146183        for (unsigned i = 0; i < args.size(); ++i) {
    147184            JSValue v = args.at(i);
     
    150187            else
    151188                ropeBuilder.append(v.toString(exec));
    152         }
     189
     190            unsigned newLength = ropeBuilder.length();
     191            if (newLength < length)
     192                overflow = true;
     193            length = newLength;
     194        }
     195
     196        if (overflow)
     197            return throwOutOfMemoryError(exec);
    153198
    154199        JSGlobalData* globalData = &exec->globalData();
Note: See TracChangeset for help on using the changeset viewer.