#25754 [NEW]: preg_replace and preg_replace_callback are crash on long matches

Ask a Question related to PHP Development, Design and Development.

  1. #1

    Default #25754 [NEW]: preg_replace and preg_replace_callback are crash on long matches

    From: ilya at lebedev dot net
    Operating system: Win32
    PHP version: 4CVS-2003-10-04 (stable)
    PHP Bug Type: Reproducible crash
    Bug description: preg_replace and preg_replace_callback are crash on long matches

    Description:
    ------------
    Regular expression from the J.Friedl's "Mastering regular expressions"
    book that matches pair html tags:
    #<tag([^>]*)>(((?!</?tag(?:[^>]*)>).)*)</tag>#si

    When between <tag> and </tag> are more then 2100 bytes (symbols), Apache
    crashes.

    Same happens without "s" modifier, if string has no "newline" codes.

    Reproduce code:
    ---------------
    ===
    preg_replace("#<tag([^>]*)>(((?!</?tag(?:[^>]*)>).)*)</tag>#si","","<tag>
    2200 symbols</tag>");
    ===
    or
    ===
    function callback (&$m) { return "";};
    preg_replace_callback
    ("#<tag([^>]*)>(((?!</?tag(?:[^>]*)>).)*)</tag>#si","callback","<tag> 2200
    symbols </tag>");
    ===

    Expected result:
    ----------------
    Match blocks bigger then 2100 symbols long.

    Actual result:
    --------------
    With more then 2100 sybmols between tags Apache crashes.

    --
    Edit bug report at [url]http://bugs.php.net/?id=25754&edit=1[/url]
    --
    Try a CVS snapshot (php4): [url]http://bugs.php.net/fix.php?id=25754&r=trysnapshot4[/url]
    Try a CVS snapshot (php5): [url]http://bugs.php.net/fix.php?id=25754&r=trysnapshot5[/url]
    Fixed in CVS: [url]http://bugs.php.net/fix.php?id=25754&r=fixedcvs[/url]
    Fixed in release: [url]http://bugs.php.net/fix.php?id=25754&r=alreadyfixed[/url]
    Need backtrace: [url]http://bugs.php.net/fix.php?id=25754&r=needtrace[/url]
    Try newer version: [url]http://bugs.php.net/fix.php?id=25754&r=oldversion[/url]
    Not developer issue: [url]http://bugs.php.net/fix.php?id=25754&r=support[/url]
    Expected behavior: [url]http://bugs.php.net/fix.php?id=25754&r=notwrong[/url]
    Not enough info: [url]http://bugs.php.net/fix.php?id=25754&r=notenoughinfo[/url]
    Submitted twice: [url]http://bugs.php.net/fix.php?id=25754&r=submittedtwice[/url]
    register_globals: [url]http://bugs.php.net/fix.php?id=25754&r=globals[/url]
    PHP 3 support discontinued: [url]http://bugs.php.net/fix.php?id=25754&r=php3[/url]
    Daylight Savings: [url]http://bugs.php.net/fix.php?id=25754&r=dst[/url]
    IIS Stability: [url]http://bugs.php.net/fix.php?id=25754&r=isapi[/url]
    Install GNU Sed: [url]http://bugs.php.net/fix.php?id=25754&r=gnused[/url]
    Floating point limitations: [url]http://bugs.php.net/fix.php?id=25754&r=float[/url]
    ilya at lebedev dot net Guest

  2. Similar Questions and Discussions

    1. #39951 [NEW]: PCRE Failed for Long Matches (Less Than MATCH_LIMIT)
      From: imacat at mail dot imacat dot idv dot tw Operating system: Linux 2.6.16.29 PHP version: 5.2.0 PHP Bug Type: PCRE...
    2. #39951 [Opn]: PCRE Failed for Long Matches (Less Than MATCH_LIMIT)
      ID: 39951 User updated by: imacat at mail dot imacat dot idv dot tw Reported By: imacat at mail dot imacat dot idv dot tw...
    3. #25394 [Com]: Segfault and Crash on long scripts.
      ID: 25394 Comment by: phpnet at baskettcase dot com Reported By: mark dot meredith at shaw dot ca Status: Bogus...
    4. #25394 [Bgs->Opn]: Segfault and Crash on long scripts.
      ID: 25394 User updated by: mark dot meredith at shaw dot ca Reported By: mark dot meredith at shaw dot ca -Status: ...
    5. #25394 [Opn->Bgs]: Segfault and Crash on long scripts.
      ID: 25394 Updated by: sniper@php.net Reported By: mark dot meredith at shaw dot ca -Status: Open +Status: ...
  3. #2

    Default #25754 [NEW]: preg_replace and preg_replace_callback are crash on long matches

    Quote Originally Posted by ilya at lebedev dot net View Post
    From: ilya at lebedev dot net
    Operating system: Win32
    PHP version: 4CVS-2003-10-04 (stable)
    PHP Bug Type: Reproducible crash
    Bug description: preg_replace and preg_replace_callback are crash on long matches

    Edit bug report at [url]http://bugs.php.net/?id=25754&edit=1[/url]
    It's an Apache stack overflow issue. You probably need to increase Apache thread stack size, which is set on Windows to 1 MB only by default (8 MB on Linux).
    ferenczy Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139