Ignore:
Timestamp:
Feb 19, 2010, 3:36:09 PM (15 years ago)
Author:
[email protected]
Message:

JSString::getIndex() calls value() to resolve the string value (is a rope)
to a UString, then passes the result to jsSingleCharacterSubstring without
checking for an exception. In case of out-of-memory the returned UString
is null(), which may result in an out-of-buounds substring being created.
This is bad.

Reviewed by Oliver Hunt.

Simple fix is to be able to get an index from a rope without resolving to
UString. This may be a useful optimization in some test cases.

The same bug exists in some other methods is JSString, these can be fixed
by changing them to call getIndex().

  • runtime/JSString.cpp:

(JSC::JSString::resolveRope):
(JSC::JSString::getStringPropertyDescriptor):

  • runtime/JSString.h:

(JSC::jsSingleCharacterSubstring):
(JSC::JSString::getIndex):
(JSC::jsSingleCharacterString):
(JSC::JSString::getStringPropertySlot):

  • runtime/UStringImpl.cpp:

(JSC::singleCharacterSubstring):

  • runtime/UStringImpl.h:

(JSC::UStringImpl::singleCharacterSubstring):

File:
1 edited

Legend:

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

    r54843 r55035  
    150150}
    151151
     152PassRefPtr<UStringImpl> singleCharacterSubstring(UStringOrRopeImpl* impl, unsigned index)
     153{
     154top:
     155    if (impl->isRope()) {
     156        URopeImpl* rope = static_cast<URopeImpl*>(impl);
     157        for (unsigned i = 0; i < rope->m_fiberCount; ++i) {
     158            UStringOrRopeImpl* currentFiber = rope->fibers(i);
     159            unsigned fiberLength = currentFiber->length();
     160            if (index < fiberLength) {
     161                impl = currentFiber;
     162                goto top;
     163            }
     164            index -= fiberLength;
     165        }
     166        CRASH();
     167    }
     168
     169    return static_cast<UStringImpl*>(impl)->singleCharacterSubstring(index);
     170}
     171
    152172} // namespace JSC
Note: See TracChangeset for help on using the changeset viewer.