Harden builtins BuildResultFromMatchInfo and URIDecodeOctets

R=yangguo@chromium.org

Review URL: https://codereview.chromium.org/286203010

git-svn-id: https://v8.googlecode.com/svn/branches/bleeding_edge@21343 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 5843a335
...@@ -1535,12 +1535,14 @@ HValue* HGraphBuilder::BuildRegExpConstructResult(HValue* length, ...@@ -1535,12 +1535,14 @@ HValue* HGraphBuilder::BuildRegExpConstructResult(HValue* length,
// Compute the size of the RegExpResult followed by FixedArray with length. // Compute the size of the RegExpResult followed by FixedArray with length.
HValue* size = length; HValue* size = length;
size = AddUncasted<HShl>(size, Add<HConstant>(kPointerSizeLog2)); // Make sure size does not exceed max regular heap object size.
size = AddUncasted<HAdd>(size, Add<HConstant>(static_cast<int32_t>( const int kHeaderSize = JSRegExpResult::kSize + FixedArray::kHeaderSize;
JSRegExpResult::kSize + FixedArray::kHeaderSize))); const int kMaxLength =
(Page::kMaxRegularHeapObjectSize - kHeaderSize) >> kPointerSizeLog2;
Add<HBoundsCheck>(size, Add<HConstant>(kMaxLength));
// Make sure size does not exceeds max regular heap object size. size = AddUncasted<HShl>(size, Add<HConstant>(kPointerSizeLog2));
Add<HBoundsCheck>(size, Add<HConstant>(Page::kMaxRegularHeapObjectSize)); size = AddUncasted<HAdd>(size, Add<HConstant>(kHeaderSize));
// Allocate the JSRegExpResult and the FixedArray in one step. // Allocate the JSRegExpResult and the FixedArray in one step.
HValue* result = Add<HAllocate>( HValue* result = Add<HAllocate>(
......
...@@ -108,23 +108,26 @@ function DoRegExpExec(regexp, string, index) { ...@@ -108,23 +108,26 @@ function DoRegExpExec(regexp, string, index) {
} }
function BuildResultFromMatchInfo(lastMatchInfo, s) { // This is kind of performance sensitive, so we want to avoid unnecessary
var numResults = NUMBER_OF_CAPTURES(lastMatchInfo) >> 1; // type checks on inputs. But we also don't want to inline it several times
var start = lastMatchInfo[CAPTURE0]; // manually, so we use a macro :-)
var end = lastMatchInfo[CAPTURE1]; macro RETURN_NEW_RESULT_FROM_MATCH_INFO(MATCHINFO, STRING)
var result = %_RegExpConstructResult(numResults, start, s); var numResults = NUMBER_OF_CAPTURES(MATCHINFO) >> 1;
result[0] = %_SubString(s, start, end); var start = MATCHINFO[CAPTURE0];
var end = MATCHINFO[CAPTURE1];
var result = %_RegExpConstructResult(numResults, start, STRING);
result[0] = %_SubString(STRING, start, end);
var j = REGEXP_FIRST_CAPTURE + 2; var j = REGEXP_FIRST_CAPTURE + 2;
for (var i = 1; i < numResults; i++) { for (var i = 1; i < numResults; i++) {
start = lastMatchInfo[j++]; start = MATCHINFO[j++];
if (start != -1) { if (start != -1) {
end = lastMatchInfo[j]; end = MATCHINFO[j];
result[i] = %_SubString(s, start, end); result[i] = %_SubString(STRING, start, end);
} }
j++; j++;
} }
return result; return result;
} endmacro
function RegExpExecNoTests(regexp, string, start) { function RegExpExecNoTests(regexp, string, start) {
...@@ -132,7 +135,7 @@ function RegExpExecNoTests(regexp, string, start) { ...@@ -132,7 +135,7 @@ function RegExpExecNoTests(regexp, string, start) {
var matchInfo = %_RegExpExec(regexp, string, start, lastMatchInfo); var matchInfo = %_RegExpExec(regexp, string, start, lastMatchInfo);
if (matchInfo !== null) { if (matchInfo !== null) {
lastMatchInfoOverride = null; lastMatchInfoOverride = null;
return BuildResultFromMatchInfo(matchInfo, string); RETURN_NEW_RESULT_FROM_MATCH_INFO(matchInfo, string);
} }
regexp.lastIndex = 0; regexp.lastIndex = 0;
return null; return null;
...@@ -175,7 +178,7 @@ function RegExpExec(string) { ...@@ -175,7 +178,7 @@ function RegExpExec(string) {
if (global) { if (global) {
this.lastIndex = lastMatchInfo[CAPTURE1]; this.lastIndex = lastMatchInfo[CAPTURE1];
} }
return BuildResultFromMatchInfo(matchIndices, string); RETURN_NEW_RESULT_FROM_MATCH_INFO(matchIndices, string);
} }
......
...@@ -84,6 +84,7 @@ function URIHexCharsToCharCode(highChar, lowChar) { ...@@ -84,6 +84,7 @@ function URIHexCharsToCharCode(highChar, lowChar) {
function URIDecodeOctets(octets, result, index) { function URIDecodeOctets(octets, result, index) {
if (!IS_STRING(result)) throw new $URIError("Internal error");
var value; var value;
var o0 = octets[0]; var o0 = octets[0];
if (o0 < 0x80) { if (o0 < 0x80) {
...@@ -148,9 +149,15 @@ function URIDecodeOctets(octets, result, index) { ...@@ -148,9 +149,15 @@ function URIDecodeOctets(octets, result, index) {
throw new $URIError("URI malformed"); throw new $URIError("URI malformed");
} }
if (value < 0x10000) { if (value < 0x10000) {
if (index < 0 || index >= result.length) {
throw new $URIError("Internal error");
}
%_TwoByteSeqStringSetChar(result, index++, value); %_TwoByteSeqStringSetChar(result, index++, value);
return index; return index;
} else { } else {
if (index < 0 || index >= result.length - 1) {
throw new $URIError("Internal error");
}
%_TwoByteSeqStringSetChar(result, index++, (value >> 10) + 0xd7c0); %_TwoByteSeqStringSetChar(result, index++, (value >> 10) + 0xd7c0);
%_TwoByteSeqStringSetChar(result, index++, (value & 0x3ff) + 0xdc00); %_TwoByteSeqStringSetChar(result, index++, (value & 0x3ff) + 0xdc00);
return index; return index;
......
...@@ -51,7 +51,7 @@ EXPECTED_FUNCTION_COUNT = 362 ...@@ -51,7 +51,7 @@ EXPECTED_FUNCTION_COUNT = 362
EXPECTED_FUZZABLE_COUNT = 329 EXPECTED_FUZZABLE_COUNT = 329
EXPECTED_CCTEST_COUNT = 6 EXPECTED_CCTEST_COUNT = 6
EXPECTED_UNKNOWN_COUNT = 5 EXPECTED_UNKNOWN_COUNT = 5
EXPECTED_BUILTINS_COUNT = 827 EXPECTED_BUILTINS_COUNT = 826
# Don't call these at all. # Don't call these at all.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment