#40754 [NEW]: substr() checks overflow

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

  1. #1

    Default #40754 [NEW]: substr() checks overflow

    From: christopher dot jones at oracle dot com
    Operating system: Enterprise Linux
    PHP version: 5CVS-2007-03-08 (CVS)
    PHP Bug Type: Strings related
    Bug description: substr() checks overflow

    Description:
    ------------
    Related to the problems fixes in today's patches for substr_count() and
    substr_compare() there are issues with substr() and substr_replace().
    Also there might be return value inconsistencies with strspn() and
    strcspn().

    Reproduce code:
    ---------------
    <?php

    $v = 2147483647; # INT_MAX on 32bit Linux

    # Tries to allocate too much memory
    var_dump(substr("abcde", 1, $v));
    var_dump(substr_replace("abcde", "x", $v, $v));

    # Functions with ill-defined behavior
    var_dump(strspn("abcde", "abc", $v, $v)); # should return 0 but gives
    false
    var_dump(strcspn("abcde", "abc", $v, $v)); # should return 0 but gives
    false

    # Crashes
    var_dump(substr_count("abcde", "abc", $v, $v)); # crashes <= 5.2.1.
    Fixed by Ilia [url]http://news.php.net/php.cvs/43456[/url]
    var_dump(substr_compare("abcde", "abc", $v, $v)); # crashes <= 5.2.1.
    Fixed by Stanislav [url]http://news.php.net/php.cvs/43453[/url]

    # Other tests (currently working)
    var_dump(stripos("abcde", "abc", $v));
    var_dump(substr_count("abcde", "abc", $v, 1));
    var_dump(substr_count("abcde", "abc", 1, $v));
    var_dump(strpos("abcde", "abc", $v));
    var_dump(stripos("abcde", "abc", $v));
    var_dump(strrpos("abcde", "abc", $v));
    var_dump(strripos("abcde", "abc", $v));
    var_dump(strncmp("abcde", "abc", $v));
    var_dump(chunk_split("abcde", $v, "abc"));
    var_dump(substr("abcde", $v, $v));
    var_dump(str_repeat("a", $v+1));

    ?>



    --
    Edit bug report at [url]http://bugs.php.net/?id=40754&edit=1[/url]
    --
    Try a CVS snapshot (PHP 4.4): [url]http://bugs.php.net/fix.php?id=40754&r=trysnapshot44[/url]
    Try a CVS snapshot (PHP 5.2): [url]http://bugs.php.net/fix.php?id=40754&r=trysnapshot52[/url]
    Try a CVS snapshot (PHP 6.0): [url]http://bugs.php.net/fix.php?id=40754&r=trysnapshot60[/url]
    Fixed in CVS: [url]http://bugs.php.net/fix.php?id=40754&r=fixedcvs[/url]
    Fixed in release: [url]http://bugs.php.net/fix.php?id=40754&r=alreadyfixed[/url]
    Need backtrace: [url]http://bugs.php.net/fix.php?id=40754&r=needtrace[/url]
    Need Reproduce Script: [url]http://bugs.php.net/fix.php?id=40754&r=needscript[/url]
    Try newer version: [url]http://bugs.php.net/fix.php?id=40754&r=oldversion[/url]
    Not developer issue: [url]http://bugs.php.net/fix.php?id=40754&r=support[/url]
    Expected behavior: [url]http://bugs.php.net/fix.php?id=40754&r=notwrong[/url]
    Not enough info: [url]http://bugs.php.net/fix.php?id=40754&r=notenoughinfo[/url]
    Submitted twice: [url]http://bugs.php.net/fix.php?id=40754&r=submittedtwice[/url]
    register_globals: [url]http://bugs.php.net/fix.php?id=40754&r=globals[/url]
    PHP 3 support discontinued: [url]http://bugs.php.net/fix.php?id=40754&r=php3[/url]
    Daylight Savings: [url]http://bugs.php.net/fix.php?id=40754&r=dst[/url]
    IIS Stability: [url]http://bugs.php.net/fix.php?id=40754&r=isapi[/url]
    Install GNU Sed: [url]http://bugs.php.net/fix.php?id=40754&r=gnused[/url]
    Floating point limitations: [url]http://bugs.php.net/fix.php?id=40754&r=float[/url]
    No Zend Extensions: [url]http://bugs.php.net/fix.php?id=40754&r=nozend[/url]
    MySQL Configuration Error: [url]http://bugs.php.net/fix.php?id=40754&r=mysqlcfg[/url]
    christopher dot jones at oracle dot com Guest

  2. Similar Questions and Discussions

    1. Help translating fread to substr
      Dear All Im having some dificulty here: I found a great PHP code by Catalin Mihaila that reads a SRC (Sinclair Spectrum $SCREEN Image Format)...
    2. [PHP-DEV] [PATCH] substr() returns false
      --=-sQWDp5Weadel0FX8XkrW Content-Type: text/plain Content-Transfer-Encoding: 7bit Hi, Even though this is documented, it is strange...
    3. substr parsing mask
      Does anyone have a short routine for displaying mask on some values and displaying the value of the last four? For example, alot of site display...
    4. [PHP] substr ?
      How can I find out if $mystring includes the character "¶"? Thought substr would do it? J
    5. InStr, substr, Mid ???
      I have a field name "tracks" of string data type that has multiple names in it (for example: calder delaware$ aqueduct ), and I want to check to...
  3. #2

    Default #40754 [Opn]: substr() checks overflow

    ID: 40754
    User updated by: christopher dot jones at oracle dot com
    Reported By: christopher dot jones at oracle dot com
    Status: Open
    Bug Type: Strings related
    Operating System: Enterprise Linux
    PHP Version: 5CVS-2007-03-08 (CVS)
    New Comment:

    I've sent a patch and testcase to Tony.


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

    [2007-03-08 00:57:37] christopher dot jones at oracle dot com

    Description:
    ------------
    Related to the problems fixes in today's patches for substr_count() and
    substr_compare() there are issues with substr() and substr_replace().
    Also there might be return value inconsistencies with strspn() and
    strcspn().

    Reproduce code:
    ---------------
    <?php

    $v = 2147483647; # INT_MAX on 32bit Linux

    # Tries to allocate too much memory
    var_dump(substr("abcde", 1, $v));
    var_dump(substr_replace("abcde", "x", $v, $v));

    # Functions with ill-defined behavior
    var_dump(strspn("abcde", "abc", $v, $v)); # should return 0 but gives
    false
    var_dump(strcspn("abcde", "abc", $v, $v)); # should return 0 but gives
    false

    # Crashes
    var_dump(substr_count("abcde", "abc", $v, $v)); # crashes <= 5.2.1.
    Fixed by Ilia [url]http://news.php.net/php.cvs/43456[/url]
    var_dump(substr_compare("abcde", "abc", $v, $v)); # crashes <= 5.2.1.
    Fixed by Stanislav [url]http://news.php.net/php.cvs/43453[/url]

    # Other tests (currently working)
    var_dump(stripos("abcde", "abc", $v));
    var_dump(substr_count("abcde", "abc", $v, 1));
    var_dump(substr_count("abcde", "abc", 1, $v));
    var_dump(strpos("abcde", "abc", $v));
    var_dump(stripos("abcde", "abc", $v));
    var_dump(strrpos("abcde", "abc", $v));
    var_dump(strripos("abcde", "abc", $v));
    var_dump(strncmp("abcde", "abc", $v));
    var_dump(chunk_split("abcde", $v, "abc"));
    var_dump(substr("abcde", $v, $v));
    var_dump(str_repeat("a", $v+1));

    ?>




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


    --
    Edit this bug report at [url]http://bugs.php.net/?id=40754&edit=1[/url]
    christopher dot jones at oracle dot com Guest

  4. #3

    Default #40754 [Opn->Csd]: substr() checks overflow

    ID: 40754
    Updated by: [email]iliaa@php.net[/email]
    Reported By: christopher dot jones at oracle dot com
    -Status: Open
    +Status: Closed
    Bug Type: Strings related
    Operating System: Enterprise Linux
    PHP Version: 5CVS-2007-03-08 (CVS)
    New Comment:

    This bug has been fixed in CVS.

    Snapshots of the sources are packaged every three hours; this change
    will be in the next snapshot. You can grab the snapshot at
    [url]http://snaps.php.net/[/url].

    Thank you for the report, and for helping us make PHP better.

    The strspn() and strcspn() is expected behavior.


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

    [2007-03-09 01:01:45] christopher dot jones at oracle dot com

    I've sent a patch and testcase to Tony.

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

    [2007-03-08 00:57:37] christopher dot jones at oracle dot com

    Description:
    ------------
    Related to the problems fixes in today's patches for substr_count() and
    substr_compare() there are issues with substr() and substr_replace().
    Also there might be return value inconsistencies with strspn() and
    strcspn().

    Reproduce code:
    ---------------
    <?php

    $v = 2147483647; # INT_MAX on 32bit Linux

    # Tries to allocate too much memory
    var_dump(substr("abcde", 1, $v));
    var_dump(substr_replace("abcde", "x", $v, $v));

    # Functions with ill-defined behavior
    var_dump(strspn("abcde", "abc", $v, $v)); # should return 0 but gives
    false
    var_dump(strcspn("abcde", "abc", $v, $v)); # should return 0 but gives
    false

    # Crashes
    var_dump(substr_count("abcde", "abc", $v, $v)); # crashes <= 5.2.1.
    Fixed by Ilia [url]http://news.php.net/php.cvs/43456[/url]
    var_dump(substr_compare("abcde", "abc", $v, $v)); # crashes <= 5.2.1.
    Fixed by Stanislav [url]http://news.php.net/php.cvs/43453[/url]

    # Other tests (currently working)
    var_dump(stripos("abcde", "abc", $v));
    var_dump(substr_count("abcde", "abc", $v, 1));
    var_dump(substr_count("abcde", "abc", 1, $v));
    var_dump(strpos("abcde", "abc", $v));
    var_dump(stripos("abcde", "abc", $v));
    var_dump(strrpos("abcde", "abc", $v));
    var_dump(strripos("abcde", "abc", $v));
    var_dump(strncmp("abcde", "abc", $v));
    var_dump(chunk_split("abcde", $v, "abc"));
    var_dump(substr("abcde", $v, $v));
    var_dump(str_repeat("a", $v+1));

    ?>




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


    --
    Edit this bug report at [url]http://bugs.php.net/?id=40754&edit=1[/url]
    iliaa@php.net 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