Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(986)

Side by Side Diff: src/ast.cc

Issue 10384053: Regexp: Fix overflow in min-match-length calculation. Crbug=126412. (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: Created 8 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | test/mjsunit/regress/regress-126412.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 944 matching lines...) Expand 10 before | Expand all | Expand 10 after
955 min_match_ = first_alternative->min_match(); 955 min_match_ = first_alternative->min_match();
956 max_match_ = first_alternative->max_match(); 956 max_match_ = first_alternative->max_match();
957 for (int i = 1; i < alternatives->length(); i++) { 957 for (int i = 1; i < alternatives->length(); i++) {
958 RegExpTree* alternative = alternatives->at(i); 958 RegExpTree* alternative = alternatives->at(i);
959 min_match_ = Min(min_match_, alternative->min_match()); 959 min_match_ = Min(min_match_, alternative->min_match());
960 max_match_ = Max(max_match_, alternative->max_match()); 960 max_match_ = Max(max_match_, alternative->max_match());
961 } 961 }
962 } 962 }
963 963
964 964
965 static int IncreaseBy(int previous, int increase) {
966 if (RegExpTree::kInfinity - previous < increase) {
967 return RegExpTree::kInfinity;
968 } else {
969 return previous + increase;
970 }
971 }
972
965 RegExpAlternative::RegExpAlternative(ZoneList<RegExpTree*>* nodes) 973 RegExpAlternative::RegExpAlternative(ZoneList<RegExpTree*>* nodes)
966 : nodes_(nodes) { 974 : nodes_(nodes) {
967 ASSERT(nodes->length() > 1); 975 ASSERT(nodes->length() > 1);
968 min_match_ = 0; 976 min_match_ = 0;
969 max_match_ = 0; 977 max_match_ = 0;
970 for (int i = 0; i < nodes->length(); i++) { 978 for (int i = 0; i < nodes->length(); i++) {
971 RegExpTree* node = nodes->at(i); 979 RegExpTree* node = nodes->at(i);
972 min_match_ += node->min_match(); 980 int node_min_match = node->min_match();
981 min_match_ = IncreaseBy(min_match_, node_min_match);
973 int node_max_match = node->max_match(); 982 int node_max_match = node->max_match();
974 if (kInfinity - max_match_ < node_max_match) { 983 max_match_ = IncreaseBy(max_match_, node_max_match);
975 max_match_ = kInfinity;
976 } else {
977 max_match_ += node->max_match();
978 }
979 } 984 }
980 } 985 }
981 986
982 987
983 CaseClause::CaseClause(Isolate* isolate, 988 CaseClause::CaseClause(Isolate* isolate,
984 Expression* label, 989 Expression* label,
985 ZoneList<Statement*>* statements, 990 ZoneList<Statement*>* statements,
986 int pos) 991 int pos)
987 : label_(label), 992 : label_(label),
988 statements_(statements), 993 statements_(statements),
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
1099 OS::SNPrintF(buffer, "%d", Smi::cast(*handle_)->value()); 1104 OS::SNPrintF(buffer, "%d", Smi::cast(*handle_)->value());
1100 str = arr; 1105 str = arr;
1101 } else { 1106 } else {
1102 str = DoubleToCString(handle_->Number(), buffer); 1107 str = DoubleToCString(handle_->Number(), buffer);
1103 } 1108 }
1104 return FACTORY->NewStringFromAscii(CStrVector(str)); 1109 return FACTORY->NewStringFromAscii(CStrVector(str));
1105 } 1110 }
1106 1111
1107 1112
1108 } } // namespace v8::internal 1113 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « no previous file | test/mjsunit/regress/regress-126412.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698