php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #18313 elusive recursion-related crash
Submitted: 2002-07-12 08:49 UTC Modified: 2002-09-11 11:36 UTC
From: admin at finance-on dot net Assigned:
Status: No Feedback Package: Reproducible crash
PHP Version: 4.2.1 OS: linux, 2.4 kernel
Private report: No CVE-ID: None
 [2002-07-12 08:49 UTC] admin at finance-on dot net
i am sorting an array of strings using uasort($a,'isoCompare').

the user function isoCompare, in its recursive variant, crashes randomly.

first, the support function charPower which remaps diacritical chars... this one is ok.

function charPower ($ch,$charPowerCaseSensitive=FALSE,$charPowerReverseOrder=FALSE) {
        $power = 0;
        $char = ($charPowerCaseSensitive ? $ch : strtoupper($ch));
        switch (ord($char)) {
                case 232: $power = 10*ord(($charPowerCaseSensitive ? "c" : "C")
                case 200: $power = 10*ord("C")+3; break;
                case 190: $power = 10*ord(($charPowerCaseSensitive ? "z" : "Z")
                case 174: $power = 10*ord("Z")+5; break;
                case 185: $power = 10*ord(($charPowerCaseSensitive ? "s" : "S")
                case 169: $power = 10*ord("S")+5; break;
                case 230: $power = 10*ord(($charPowerCaseSensitive ? "c" : "C")
                case 198: $power = 10*ord("C")+6; break;
                case 240: $power = 10*ord(($charPowerCaseSensitive ? "d" : "D")
                case 208: $power = 10*ord("D")+5; break;
                default: $power = 10*ord($char);
        }
        return ($charPowerReverseOrder ? ((-1)*$power) : $power);
} ;

now the recursive isoCompare...

function isoCompare ($s1,$s2) {
        $len1 = strlen($s1);
        $len2 = strlen($s2);
        if ($len1==0 || $len2==0) {
          $ret = $len1 - $len2;
          if (!$ret) return 0;
          else return $ret > 0 ? +1 : -1;
        } ;
        $c1 = charPower($s1);
        $c2 = charPower($s2);
        $power1 = charPower($c1) ;
        $power2 = charPower($c2) ;
        if ($power1==$power2) {
          $ret = isoCompare(substr($s1,1), substr($s2,1));
          return $ret;
        } else {
          $ret = $power1-$power2;
          return $ret > 0 ? +1 : -1;
        }
}

the iterative version works fine:

function isoCompare ($s1, $s2) {
  global $isadmin;
    $i = 0; $ret = 0;
    while (!$ret) {
      $len1 = strlen($s1);
      $len2 = strlen($s2);
      if ($len1 == 0 && $len2 == 0) $ret = 0;
      elseif ($len1 == 0) $ret = 1;
      elseif ($len2 == 0) $ret = -1 ;
      else {
        $power1 = charPower(substr($s1,0,1)) ;
        $power2 = charPower(substr($s2,0,1)) ;
        if ($power1 > $power2) $ret = 1;
        elseif ($power2 > $power1) $ret = -1;
        else {
          $s1 = substr($s1,1);
          $s2 = substr($s2,1);
        } ;
      } ;
    } ; // while
    return $ret;
} ;

my setup:

./configure \
--with-config-file-path=/usr/local/lib \
--with-zlib \
--with-mysql=/usr/local/mysql \
--with-exec-dir=/usr/local/safe_mode --enable-track-vars=yes \
--enable-magic-quotes=yes --disable-debug \
--with-pdflib \
--with-xml \
--with-sablot=/usr/local/lib \
--with-expat=/usr/local/lib \
--enable-sysvsem \
--enable-sysvshm \
--with-gd \
--with-iconv \
--with-curl=/usr/local/curl \
--with-apxs=/usr/local/apache/bin/apxs

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-07-12 08:53 UTC] admin at finance-on dot net
the isoCompare, when used on a page, will cause it to show up as "document contains no data" ... on some reloads, whereas sometimes it will be fine, using the same inputs.
i have not been able to find anything that could be tweaked to change the frequency of crashes. they seem random.

as a temporary measure we have moved to the iterative version. i'm quite worried about whether there is a problem with our setup or is this actually an issue in php 4.2.x -- we have not encountered this problem before, the code used to run fine.
 [2002-07-12 08:56 UTC] sander@php.net
Thank you for this bug report. To properly diagnose the problem, we
need a backtrace to see what is happening behind the scenes. To
find out how to generate a backtrace, please read
http://bugs.php.net/bugs-generating-backtrace.php

Once you have generated a backtrace, please submit it to this bug
report and change the status back to "Open". Thank you for helping
us make PHP better.

Also, please simplify your sample script. Please strip it down to a 5-10 lines standalone samplescript that reproduces your problem.
 [2002-09-11 11:36 UTC] sniper@php.net
No feedback was provided. The bug is being suspended because
we assume that you are no longer experiencing the problem.
If this is not the case and you are able to provide the
information that was requested earlier, please do so and
change the status of the bug back to "Open". Thank you.


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Dec 26 12:01:30 2024 UTC