Ignore:
Timestamp:
Apr 18, 2009, 4:50:03 PM (16 years ago)
Author:
[email protected]
Message:

2009-04-18 Sam Weinig <[email protected]>

Reviewed by Mark Rowe.

Fix for <rdar://problem/5861045>
A little bit of hardening for UString.

  • runtime/UString.cpp: (JSC::concatenate): (JSC::UString::append):
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/runtime/UString.cpp

    r42282 r42644  
    511511    } else if (rep == base && !base->isShared()) {
    512512        // this is direct and has refcount of 1 (so we can just alter it directly)
    513         if (!expandCapacity(rep.get(), thisOffset + length))
     513        int newCapacity = thisOffset + length;
     514        if (newCapacity < thisOffset)
     515            CRASH();
     516        if (!expandCapacity(rep.get(), newCapacity))
    514517            rep = &UString::Rep::null();
    515518        if (rep->data()) {
     
    520523    } else if (thisOffset + thisSize == base->usedCapacity && thisSize >= minShareSize) {
    521524        // this reaches the end of the buffer - extend it if it's long enough to append to
    522         if (!expandCapacity(rep.get(), thisOffset + length))
     525        int newCapacity = thisOffset + length;
     526        if (newCapacity < thisOffset)
     527            CRASH();
     528        if (!expandCapacity(rep.get(), newCapacity))
    523529            rep = &UString::Rep::null();
    524530        if (rep->data()) {
     
    565571    } else if (rep == base && !base->isShared()) {
    566572        // this is direct and has refcount of 1 (so we can just alter it directly)
    567         expandCapacity(rep.get(), thisOffset + length);
     573        int newCapacity = thisOffset + length;
     574        if (newCapacity < thisOffset)
     575            CRASH();
     576        expandCapacity(rep.get(), newCapacity);
    568577        UChar* d = rep->data();
    569578        if (d) {
     
    575584    } else if (thisOffset + thisSize == base->usedCapacity && thisSize >= minShareSize) {
    576585        // this string reaches the end of the buffer - extend it
    577         expandCapacity(rep.get(), thisOffset + length);
     586        int newCapacity = thisOffset + length;
     587        if (newCapacity < thisOffset)
     588            CRASH();
     589        expandCapacity(rep.get(), newCapacity);
    578590        UChar* d = rep->data();
    579591        if (d) {
     
    637649        //   string does more harm than good
    638650        // - however, if b qualifies for prepend and is longer than a, we'd rather prepend
     651       
    639652        UString x(a);
    640         x.expandCapacity(aOffset + length);
     653        int capacity = aOffset + length;
     654        if (capacity < aOffset)
     655            CRASH();
     656        x.expandCapacity(capacity);
    641657        if (!a->data() || !x.data())
    642658            return 0;
     
    9881004    } else if (m_rep == base && !base->isShared()) {
    9891005        // this is direct and has refcount of 1 (so we can just alter it directly)
    990         expandCapacity(thisOffset + length);
     1006        int newCapacity = thisOffset + length;
     1007        if (newCapacity < thisOffset)
     1008            CRASH();
     1009        expandCapacity(newCapacity);
    9911010        if (data()) {
    9921011            copyChars(m_rep->data() + thisSize, t.data(), tSize);
     
    9961015    } else if (thisOffset + thisSize == base->usedCapacity && thisSize >= minShareSize) {
    9971016        // this reaches the end of the buffer - extend it if it's long enough to append to
    998         expandCapacity(thisOffset + length);
     1017        int newCapacity = thisOffset + length;
     1018        if (newCapacity < thisOffset)
     1019            CRASH();
     1020        expandCapacity(newCapacity);
    9991021        if (data()) {
    10001022            copyChars(m_rep->data() + thisSize, t.data(), tSize);
     
    10551077    } else if (m_rep == base && !base->isShared()) {
    10561078        // this is direct and has refcount of 1 (so we can just alter it directly)
    1057         expandCapacity(thisOffset + length + 1);
     1079        int newCapacity = thisOffset + length + 1;
     1080        if (newCapacity < thisOffset)
     1081            CRASH();
     1082        expandCapacity(newCapacity);
    10581083        UChar* d = m_rep->data();
    10591084        if (d) {
     
    10641089    } else if (thisOffset + length == base->usedCapacity && length >= minShareSize) {
    10651090        // this reaches the end of the string - extend it and share
    1066         expandCapacity(thisOffset + length + 1);
     1091        int newCapacity = thisOffset + length + 1;
     1092        if (newCapacity < thisOffset)
     1093            CRASH();
     1094        expandCapacity(newCapacity);
    10671095        UChar* d = m_rep->data();
    10681096        if (d) {
Note: See TracChangeset for help on using the changeset viewer.