Changeset 31388 in webkit for trunk/JavaScriptCore/pcre
- Timestamp:
- Mar 27, 2008, 11:41:17 PM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/pcre/pcre_compile.cpp
r29110 r31388 1986 1986 } 1987 1987 1988 static inline int multiplyWithOverflowCheck(int a, int b) 1989 { 1990 if (!a || !b) 1991 return 0; 1992 if (a > MAX_PATTERN_SIZE / b) 1993 return -1; 1994 return a * b; 1995 } 1996 1988 1997 static int calculateCompiledPatternLength(const UChar* pattern, int patternLength, JSRegExpIgnoreCaseOption ignoreCase, 1989 1998 CompileData& cd, ErrorCode& errorcode) … … 1992 2001 amount of store required to hold the compiled code. This does not have to be 1993 2002 perfect as long as errors are overestimates. */ 1994 2003 2004 if (patternLength > MAX_PATTERN_SIZE) { 2005 errorcode = ERR16; 2006 return -1; 2007 } 2008 1995 2009 int length = 1 + LINK_SIZE; /* For initial BRA plus length */ 1996 2010 int branch_extra = 0; … … 2414 2428 bracket set. */ 2415 2429 2430 int repeatsLength; 2416 2431 if (minRepeats == 0) { 2417 2432 length++; 2418 if (maxRepeats > 0) length += (maxRepeats - 1) * (duplength + 3 + 2 * LINK_SIZE); 2433 if (maxRepeats > 0) { 2434 repeatsLength = multiplyWithOverflowCheck(maxRepeats - 1, duplength + 3 + 2 * LINK_SIZE); 2435 if (repeatsLength < 0) { 2436 errorcode = ERR16; 2437 return -1; 2438 } 2439 length += repeatsLength; 2440 if (length > MAX_PATTERN_SIZE) { 2441 errorcode = ERR16; 2442 return -1; 2443 } 2444 } 2419 2445 } 2420 2446 … … 2426 2452 2427 2453 else { 2428 length += (minRepeats - 1) * duplength; 2429 if (maxRepeats > minRepeats) /* Need this test as maxRepeats=-1 means no limit */ 2430 length += (maxRepeats - minRepeats) * (duplength + 3 + 2 * LINK_SIZE) 2431 - (2 + 2 * LINK_SIZE); 2454 repeatsLength = multiplyWithOverflowCheck(minRepeats - 1, duplength); 2455 if (repeatsLength < 0) { 2456 errorcode = ERR16; 2457 return -1; 2458 } 2459 length += repeatsLength; 2460 if (maxRepeats > minRepeats) { /* Need this test as maxRepeats=-1 means no limit */ 2461 repeatsLength = multiplyWithOverflowCheck(maxRepeats - minRepeats, duplength + 3 + 2 * LINK_SIZE); 2462 if (repeatsLength < 0) { 2463 errorcode = ERR16; 2464 return -1; 2465 } 2466 length += repeatsLength - (2 + 2 * LINK_SIZE); 2467 } 2468 if (length > MAX_PATTERN_SIZE) { 2469 errorcode = ERR16; 2470 return -1; 2471 } 2432 2472 } 2433 2473
Note:
See TracChangeset
for help on using the changeset viewer.