Professional Web Applications Themes

#25512 [Bgs]: preg_replace Offset error - PHP Development

ID: 25512 User updated by: koni at 2complex dot net Reported By: koni at 2complex dot net Status: Bogus Bug Type: Reproducible crash Operating System: Windows XP PHP Version: 4.3.3 New Comment: hey, this is a SERIOUS BUG REPORT, PHP can NOT preg_replace this code. I am sorry if this was the text that the user submitted in my forum and I dont know how to reproduce the problem with another code so I had to submit the original Code. I am sorry if you feel offended but I think you should be a lot more objective about this problem. ...

  1. #1

    Default #25512 [Bgs]: preg_replace Offset error

    ID: 25512
    User updated by: koni at 2complex dot net
    Reported By: koni at 2complex dot net
    Status: Bogus
    Bug Type: Reproducible crash
    Operating System: Windows XP
    PHP Version: 4.3.3
    New Comment:

    hey, this is a SERIOUS BUG REPORT, PHP can NOT preg_replace this code.
    I am sorry if this was the text that the user submitted in my forum and
    I dont know how to reproduce the problem with another code so I had to
    submit the original Code.

    I am sorry if you feel offended but I think you should be a lot more
    objective about this problem. Forget about the content and look at the
    bug.


    Previous Comments:
    ------------------------------------------------------------------------

    [2003-09-12 08:19:34] [email]sasphp.net[/email]

    Nice signature. Go away

    ------------------------------------------------------------------------

    [2003-09-12 07:15:15] koni at 2complex dot net

    Description:
    ------------
    I wanted to write a vbb code style for a new forum and I used nl2br to
    format the mysql data into html. As there was a special
    Code:
     ...
    area in my vbb code which used the html <pre> ... </pre>
    command the format the spaces correctly, I saw that nl2br changes \n
    into <br />\n and therefor <pre> shows 2 lines instead of 1. As there
    1. is no option for nl2br to either replace with <br /> or < br/>\n, I
    wrote a small Code to preg_replace the code between the
    Code:
     ..
    commands with a placeholder, then nl2br the whole thing and
    then replace the placeholder again with the code. This did work fine
    .... until I used the following ascii figure between the [code]
    commands:

    * g o a t s e x * g o a t s e x * g o a t s e x *
    g g
    o / \ \ / \ o
    a| | \ | | a
    t| `. | | : t
    s` | | \| | s
    e \ | / / \ --__ \ : e
    x \ \/ _--~~ ~--__| \ | x
    * \ \_-~ ~-_\ | *
    g \_ \ _.--------.______\| | g
    o \ \______// _ ___ _ (_(__> \ | o
    a \ . C ___) ______ (_(____> | / a
    t /\ | C ____)/ \ (_____> |_/ t
    s / /\| C_____) | (___> / \ s
    e | ( _C_____)\______/ // _/ / \ e
    x | \ |__ \_________// (__/ | x
    * | \ \____) `---- --' | *
    g | \_ ___\ /_ _/ | g
    o | / | | \ | o
    a | | / \ \ | a
    t | / / | | \ |t
    s | / / \__/\___/ | |s
    e | / / | | | |e
    x | | | | | |x
    * g o a t s e x * g o a t s e x * g o a t e x *

    This gave me the following:

    Warning: Compilation failed: missing ) at offset 1412 in
    c:\phpdev\www\tattered\functions.php on line 788

    and line 788 is:

    $message =
    preg_replace("#".escape($match)."#si","##$counter# #",$message);

    Every preg_replace crashes when it has to replace the above-mentioned
    code.

    Reproduce code:
    ---------------
    function escape($string) {
    $list = array("[" => "\[", "]" => "\]", "/" => "\/");
    foreach($list as $search => $replace) {
    $string = str_replace($search, $replace, $string);
    }
    return $string;
    }


    preg_match_all("#\[code\]([^\[]*)\[\/code\]#si",$message,$matches);

    foreach($matches[0] as $counter => $match) {
    $message =
    preg_replace("#".escape($match)."#si","##$counter# #",$message);
    }
    $message = nl2br($message);
    foreach($matches[0] as $counter => $match) {
    $message =
    preg_replace("/##$counter##/si",$match,$message);
    }


    Expected result:
    ----------------
    g o a t s e x * g o a t s e x * g o a t s e x *
    g g
    o / \ \ / \ o
    a| | \ | | a
    t| `. | | : t
    s` | | \| | s
    e \ | / / \ --__ \ : e
    x \ \/ _--~~ ~--__| \ | x
    * \ \_-~ ~-_\ | *
    g \_ \ _.--------.______\| | g
    o \ \______// _ ___ _ (_(__> \ | o
    a \ . C ___) ______ (_(____> | / a
    t /\ | C ____)/ \ (_____> |_/ t
    s / /\| C_____) | (___> / \ s
    e | ( _C_____)\______/ // _/ / \ e
    x | \ |__ \_________// (__/ | x
    * | \ \____) `---- --' | *
    g | \_ ___\ /_ _/ | g
    o | / | | \ | o
    a | | / \ \ | a
    t | / / | | \ |t
    s | / / \__/\___/ | |s
    e | / / | | | |e
    x | | | | | |x
    * g o a t s e x * g o a t s e x * g o a t e x *


    Actual result:
    --------------
    g o a t s e x * g o a t s e x * g o a t s e x *

    g g

    o / \ \ / \ o

    a| | \ | | a

    t| `. | | : t

    s` | | \| | s

    e \ | / / \ --__ \ : e

    x \ \/ _--~~ ~--__| \ | x

    * \ \_-~ ~-_\ | *

    g \_ \ _.--------.______\| | g

    o \ \______// _ ___ _ (_(__> \ | o

    a \ . C ___) ______ (_(____> | / a

    t /\ | C ____)/ \ (_____> |_/ t

    s / /\| C_____) | (___> / \ s

    e | ( _C_____)\______/ // _/ / \ e

    x | \ |__ \_________// (__/ | x

    * | \ \____) `---- --' | *

    g | \_ ___\ /_ _/ | g

    o | / | | \ | o

    a | | / \ \ | a

    t | / / | | \ |t

    s | / / \__/\___/ | |s

    e | / / | | |
    |e
    x | | | | |
    |x
    * g o a t s e x * g o a t s e x * g o a t e x *




    ------------------------------------------------------------------------


    --
    Edit this bug report at http://bugs.php.net/?id=25512&edit=1
    koni at 2complex dot net Guest

  2. #2

    Default #25512 [Bgs]: preg_replace Offset error

    ID: 25512
    Updated by: [email]pollitaphp.net[/email]
    Reported By: koni at 2complex dot net
    Status: Bogus
    Bug Type: Reproducible crash
    Operating System: Windows XP
    PHP Version: 4.3.3
    New Comment:

    Sorry, but your problem does not imply a bug in PHP itself. For a
    list of more appropriate places to ask for help using PHP, please
    visit [url]http://www.php.net/support.php[/url] as this bug system is not the
    appropriate forum for asking support questions.

    Thank you for your interest in PHP.

    Your code is inherently flawed. What you describe can be correctly
    handled with a single regex expression (albiet a complex one).

    However since this is a bug reporting database and not a support forum,
    I suggest you try one of the resources named in the paragraphs above.


    Previous Comments:
    ------------------------------------------------------------------------

    [2003-09-12 09:00:57] koni at 2complex dot net

    hey, this is a SERIOUS BUG REPORT, PHP can NOT preg_replace this code.
    I am sorry if this was the text that the user submitted in my forum and
    I dont know how to reproduce the problem with another code so I had to
    submit the original Code.

    I am sorry if you feel offended but I think you should be a lot more
    objective about this problem. Forget about the content and look at the
    bug.

    ------------------------------------------------------------------------

    [2003-09-12 08:19:34] [email]sasphp.net[/email]

    Nice signature. Go away

    ------------------------------------------------------------------------

    [2003-09-12 07:15:15] koni at 2complex dot net

    Description:
    ------------
    I wanted to write a vbb code style for a new forum and I used nl2br to
    format the mysql data into html. As there was a special
    Code:
     ...
    area in my vbb code which used the html <pre> ... </pre>
    command the format the spaces correctly, I saw that nl2br changes \n
    into <br />\n and therefor <pre> shows 2 lines instead of 1. As there
    1. is no option for nl2br to either replace with <br /> or < br/>\n, I
    wrote a small Code to preg_replace the code between the
    Code:
     ..
    commands with a placeholder, then nl2br the whole thing and
    then replace the placeholder again with the code. This did work fine
    .... until I used the following ascii figure between the [code]
    commands:

    * g o a t s e x * g o a t s e x * g o a t s e x *
    g g
    o / \ \ / \ o
    a| | \ | | a
    t| `. | | : t
    s` | | \| | s
    e \ | / / \ --__ \ : e
    x \ \/ _--~~ ~--__| \ | x
    * \ \_-~ ~-_\ | *
    g \_ \ _.--------.______\| | g
    o \ \______// _ ___ _ (_(__> \ | o
    a \ . C ___) ______ (_(____> | / a
    t /\ | C ____)/ \ (_____> |_/ t
    s / /\| C_____) | (___> / \ s
    e | ( _C_____)\______/ // _/ / \ e
    x | \ |__ \_________// (__/ | x
    * | \ \____) `---- --' | *
    g | \_ ___\ /_ _/ | g
    o | / | | \ | o
    a | | / \ \ | a
    t | / / | | \ |t
    s | / / \__/\___/ | |s
    e | / / | | | |e
    x | | | | | |x
    * g o a t s e x * g o a t s e x * g o a t e x *

    This gave me the following:

    Warning: Compilation failed: missing ) at offset 1412 in
    c:\phpdev\www\tattered\functions.php on line 788

    and line 788 is:

    $message =
    preg_replace("#".escape($match)."#si","##$counter# #",$message);

    Every preg_replace crashes when it has to replace the above-mentioned
    code.

    Reproduce code:
    ---------------
    function escape($string) {
    $list = array("[" => "\[", "]" => "\]", "/" => "\/");
    foreach($list as $search => $replace) {
    $string = str_replace($search, $replace, $string);
    }
    return $string;
    }


    preg_match_all("#\[code\]([^\[]*)\[\/code\]#si",$message,$matches);

    foreach($matches[0] as $counter => $match) {
    $message =
    preg_replace("#".escape($match)."#si","##$counter# #",$message);
    }
    $message = nl2br($message);
    foreach($matches[0] as $counter => $match) {
    $message =
    preg_replace("/##$counter##/si",$match,$message);
    }


    Expected result:
    ----------------
    g o a t s e x * g o a t s e x * g o a t s e x *
    g g
    o / \ \ / \ o
    a| | \ | | a
    t| `. | | : t
    s` | | \| | s
    e \ | / / \ --__ \ : e
    x \ \/ _--~~ ~--__| \ | x
    * \ \_-~ ~-_\ | *
    g \_ \ _.--------.______\| | g
    o \ \______// _ ___ _ (_(__> \ | o
    a \ . C ___) ______ (_(____> | / a
    t /\ | C ____)/ \ (_____> |_/ t
    s / /\| C_____) | (___> / \ s
    e | ( _C_____)\______/ // _/ / \ e
    x | \ |__ \_________// (__/ | x
    * | \ \____) `---- --' | *
    g | \_ ___\ /_ _/ | g
    o | / | | \ | o
    a | | / \ \ | a
    t | / / | | \ |t
    s | / / \__/\___/ | |s
    e | / / | | | |e
    x | | | | | |x
    * g o a t s e x * g o a t s e x * g o a t e x *


    Actual result:
    --------------
    g o a t s e x * g o a t s e x * g o a t s e x *

    g g

    o / \ \ / \ o

    a| | \ | | a

    t| `. | | : t

    s` | | \| | s

    e \ | / / \ --__ \ : e

    x \ \/ _--~~ ~--__| \ | x

    * \ \_-~ ~-_\ | *

    g \_ \ _.--------.______\| | g

    o \ \______// _ ___ _ (_(__> \ | o

    a \ . C ___) ______ (_(____> | / a

    t /\ | C ____)/ \ (_____> |_/ t

    s / /\| C_____) | (___> / \ s

    e | ( _C_____)\______/ // _/ / \ e

    x | \ |__ \_________// (__/ | x

    * | \ \____) `---- --' | *

    g | \_ ___\ /_ _/ | g

    o | / | | \ | o

    a | | / \ \ | a

    t | / / | | \ |t

    s | / / \__/\___/ | |s

    e | / / | | |
    |e
    x | | | | |
    |x
    * g o a t s e x * g o a t s e x * g o a t e x *




    ------------------------------------------------------------------------


    --
    Edit this bug report at http://bugs.php.net/?id=25512&edit=1
    pollita@php.net Guest

Similar Threads

  1. preg_replace error?
    By Geoff Cox in forum PHP Development
    Replies: 10
    Last Post: November 22nd, 10:05 PM
  2. #26281 [Opn->Ver]: switch on string offset crashes w/bus error
    By iliaa@php.net in forum PHP Development
    Replies: 0
    Last Post: November 18th, 03:02 AM
  3. #25512 [NEW]: preg_replace Offset error
    By koni at 2complex dot net in forum PHP Development
    Replies: 0
    Last Post: September 12th, 11:16 AM
  4. Perl Palm::PDB modules Error: Bad AppInfo offset:
    By psyshrike in forum PERL Miscellaneous
    Replies: 0
    Last Post: September 3rd, 12:39 AM
  5. Replies: 0
    Last Post: August 8th, 09:25 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not 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