Changeset 41842 in webkit for trunk/JavaScriptCore/pcre


Ignore:
Timestamp:
Mar 19, 2009, 1:32:49 PM (16 years ago)
Author:
[email protected]
Message:

JavaScriptCore:

2009-03-19 Geoffrey Garen <[email protected]>

Reviewed by Sam Weinig.


Fixed <rdar://problem/6603562> REGRESSION (Safari 4): regular expression
pattern size limit lower than Safari 3.2, other browsers, breaks SAP (14873)


Bumped the pattern size limit to 1MB, and standardized it between PCRE
and WREC. (Empirical testing says that we can easily compile a 1MB regular
expression without risking a hang. Other browsers support bigger regular
expressions, but also hang.)


SunSpider reports no change.


I started with a patch posted to Bugzilla by Erik Corry ([email protected]).


  • pcre/pcre_internal.h: (put3ByteValue): (get3ByteValue): (put3ByteValueAndAdvance): (putLinkValueAllowZero): (getLinkValueAllowZero): Made PCRE's "LINK_SIZE" (the number of bytes used to record jumps between bytecodes) 3, to accomodate larger potential jumps. Bumped PCRE's "MAX_PATTERN_SIZE" to 1MB. (Technically, at this LINK_SIZE, we can support even larger patterns, but we risk a hang during compilation, and it's not clear that such large patterns are important on the web.)
  • wrec/WREC.cpp: (JSC::WREC::Generator::compileRegExp): Match PCRE's maximum pattern size, to avoid quirks between platforms.

LayoutTests:

2009-03-19 Geoffrey Garen <[email protected]>

Reviewed by Sam Weinig.


Made two layout tests less agressive, to accomodate a change I made
for <rdar://problem/6603562> REGRESSION (Safari 4): regular expression
pattern size limit lower than Safari 3.2, other browsers, breaks SAP (14873)

  • fast/js/regexp-charclass-crash-expected.txt:
  • fast/js/regexp-charclass-crash.html: Explicitly limit the number of iterations in the test loop. Otherwise, regular expression engines supporting very long patterns take a very very very long time to run this test.
  • fast/js/resources/regexp-overflow.js: Made the "too big" regexp in this test even bigger, to match our new limit.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/pcre/pcre_internal.h

    r39554 r41842  
    8686patterns up to 64K long. */
    8787
    88 #define LINK_SIZE   2
     88#define LINK_SIZE   3
    8989
    9090/* Define DEBUG to get debugging output on stdout. */
     
    125125}
    126126
     127static inline void put3ByteValue(unsigned char* opcodePtr, int value)
     128{
     129    ASSERT(value >= 0 && value <= 0xFFFFFF);
     130    opcodePtr[0] = value >> 16;
     131    opcodePtr[1] = value >> 8;
     132    opcodePtr[2] = value;
     133}
     134
    127135static inline int get2ByteValue(const unsigned char* opcodePtr)
    128136{
    129137    return (opcodePtr[0] << 8) | opcodePtr[1];
     138}
     139
     140static inline int get3ByteValue(const unsigned char* opcodePtr)
     141{
     142    return (opcodePtr[0] << 16) | (opcodePtr[1] << 8) | opcodePtr[2];
    130143}
    131144
     
    136149}
    137150
     151static inline void put3ByteValueAndAdvance(unsigned char*& opcodePtr, int value)
     152{
     153    put3ByteValue(opcodePtr, value);
     154    opcodePtr += 3;
     155}
     156
    138157static inline void putLinkValueAllowZero(unsigned char* opcodePtr, int value)
    139158{
     159#if LINK_SIZE == 3
     160    put3ByteValue(opcodePtr, value);
     161#elif LINK_SIZE == 2
    140162    put2ByteValue(opcodePtr, value);
     163#else
     164#   error LINK_SIZE not supported.
     165#endif
    141166}
    142167
    143168static inline int getLinkValueAllowZero(const unsigned char* opcodePtr)
    144169{
     170#if LINK_SIZE == 3
     171    return get3ByteValue(opcodePtr);
     172#elif LINK_SIZE == 2
    145173    return get2ByteValue(opcodePtr);
    146 }
    147 
    148 #define MAX_PATTERN_SIZE (1 << 16)
     174#else
     175#   error LINK_SIZE not supported.
     176#endif
     177}
     178
     179#define MAX_PATTERN_SIZE 1024 * 1024 // Derived by empirical testing of compile time in PCRE and WREC.
     180COMPILE_ASSERT(MAX_PATTERN_SIZE < (1 << (8 * LINK_SIZE)), pcre_max_pattern_fits_in_bytecode);
    149181
    150182static inline void putLinkValue(unsigned char* opcodePtr, int value)
Note: See TracChangeset for help on using the changeset viewer.