Changeset 60328 in webkit for trunk/JavaScriptCore/runtime


Ignore:
Timestamp:
May 27, 2010, 4:09:48 PM (15 years ago)
Author:
Darin Adler
Message:

2010-05-26 Darin Adler <Darin Adler>

Reviewed by Kent Tamura.

Null characters handled incorrectly in ToNumber conversion
https://bugs.webkit.org/show_bug.cgi?id=38088

  • runtime/JSGlobalObjectFunctions.cpp: (JSC::parseInt): Changed code to use UTF8String().data() instead of ascii() to fix the thread safety issue. Code path is covered by existing tests in run-javascriptcore-tests. (JSC::parseFloat): Moved comment to UString::toDouble since the issue affects all clients, not just parseFloat. Specifically, this also affects standard JavaScript numeric conversion, ToNumber.
  • runtime/UString.cpp: (JSC::UString::toDouble): Added a comment about incorrect space skipping. Changed trailing junk check to use the length of the CString instead of checking for a null character. Also got rid of a little unneeded logic in the case where we tolerate trailing junk.

2010-05-26 Darin Adler <Darin Adler>

Reviewed by Kent Tamura.

Null characters handled incorrectly in ToNumber conversion
https://bugs.webkit.org/show_bug.cgi?id=38088

  • fast/js/ToNumber-expected.txt: Updated for new tests and to expect PASS for two null character tests.
  • fast/js/ToNumber.js: Added more test cases.
  • fast/js/parseFloat-expected.txt: Updated for new test case.
  • fast/js/script-tests/parseFloat.js: Added a test case.
Location:
trunk/JavaScriptCore/runtime
Files:
2 edited

Legend:

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

    r58224 r60328  
    242242
    243243    if (number >= mantissaOverflowLowerBound) {
    244         // FIXME: It is incorrect to use UString::ascii() here because it's not thread-safe.
    245244        if (radix == 10)
    246             number = WTF::strtod(s.substr(firstDigitPosition, p - firstDigitPosition).ascii(), 0);
     245            number = WTF::strtod(s.substr(firstDigitPosition, p - firstDigitPosition).UTF8String().data(), 0);
    247246        else if (radix == 2 || radix == 4 || radix == 8 || radix == 16 || radix == 32)
    248             number = parseIntOverflow(s.substr(firstDigitPosition, p - firstDigitPosition).ascii(), p - firstDigitPosition, radix);
     247            number = parseIntOverflow(s.substr(firstDigitPosition, p - firstDigitPosition).UTF8String().data(), p - firstDigitPosition, radix);
    249248    }
    250249
     
    271270        return 0;
    272271
    273     // FIXME: UString::toDouble will ignore leading ASCII spaces, but we need to ignore
    274     // other StrWhiteSpaceChar values as well.
    275272    return s.toDouble(true /*tolerant*/, false /* NaN for empty string */);
    276273}
  • trunk/JavaScriptCore/runtime/UString.cpp

    r59969 r60328  
    263263    // non-ASCII characters to UTF-8, so the UTF8String does quite a bit of
    264264    // unnecessary work.
     265
     266    // FIXME: The space skipping code below skips only ASCII spaces, but callers
     267    // need to skip all StrWhiteSpace. The isStrWhiteSpace function does the
     268    // right thing but requires UChar, not char, for its argument.
     269
    265270    CString s = UTF8String();
    266271    if (s.isNull())
     
    325330    }
    326331
    327     // allow trailing white space
    328     while (isASCIISpace(*c))
    329         c++;
    330     // don't allow anything after - unless tolerant=true
    331     // FIXME: If string contains a U+0000 character, then this check is incorrect.
    332     if (!tolerateTrailingJunk && *c != '\0')
    333         d = NaN;
     332    if (!tolerateTrailingJunk) {
     333        // allow trailing white space
     334        while (isASCIISpace(*c))
     335            c++;
     336        if (c != s.data() + s.length())
     337            d = NaN;
     338    }
    334339
    335340    return d;
Note: See TracChangeset for help on using the changeset viewer.