php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #1578 Arrays of arrays breaking the parser
Submitted: 1999-06-21 18:58 UTC Modified: 2002-06-16 08:32 UTC
From: jesusmc at scripps dot edu Assigned:
Status: Not a bug Package: Reproducible Crash
PHP Version: 3.0.9 OS: Solaris 2.5.1
Private report: No CVE-ID: None
 [1999-06-21 18:58 UTC] jesusmc at scripps dot edu
Problem:

A script making use of arrays of arrays breaks PHP 3.0.8 and 3.0.9, works with PHP 3.0.7
I coredumps or fails giving the message or both. When it fails, it gives the messages:

"
...
<br>
<b>Warning</b>:  Variable $atom is not an array or string in <b>clu2.php3</b> on line <b>62</b><br>
<br>
<b>Warning</b>:  Variable $atom is not an array or string in <b>clu2.php3</b> on line <b>63</b><br>
<br>
<b>Warning</b>:  Variable $atom is not an array or string in <b>clu2.php3</b> on line <b>64</b><br>
<br>
<b>Warning</b>:  Variable $atom is not an array or string in <b>clu2.php3</b> on line <b>65</b><br>
<br>
<b>Warning</b>:  Variable $atom is not an array or string in <b>clu2.php3</b> on line <b>66</b><br>
...
"

Consistently the first entry works and the rest don't.

The following is the script that break PHP 3.0.8 and 3.0.9 compiled as module of Apache or as stand alone CGI. It works OK with 3.0.7

In all cases, PHP was compiled using (CGI case example):
./configure --prefix=/home/jesusmc/devel/php3 --with-gd=/asd/metallo1/database/gd1.3 --with-msql=/home/jesusmc/devel/msql --with-config-file-path=/homes/jesusmc/devel/php3 --enable-track-vars --enable-magic-quotes --with-mysql=/home/jesusmc/devel/mysql --with-pgsql=/home/jesusmc/devel/pgsql

Script cluster.php3

<?php
// to pre-calculate the distances in clusters
// $Id: cluster.php3,v 1.1 1999/06/17 22:51:39 jesusmc Exp $
 
 
 
  /* 
   * function to display contents of an array 
   * appropriately indented with tabs
   */
function print_array($valsarr,$tab="") {
        static $tab;
        while ( list($var,$value) = each($valsarr) ) {
          if (!is_array($value)) {
                echo $tab."VARIABLE: ".$var." -> VALUE: ".$value."<BR>\n";
          } else {  // item is itself an array
                echo $tab."VARIABLE: ".$var." is an array<BR>\n";
                print_array($value,$tab.="\t");
          }
        }
        $tab = substr($tab,0,-1);
}
 
function coords($obj) {
        return array("x"=>$obj["x"],"y"=>$obj["y"],"z"=>$obj["z"]);
}
 
function getdist($coord1,$coord2) {
        $d2 = 0;
        while(list($k,$v) = each($coord1)) {
                $d2 += pow(($coord1[$k] - $coord2[$k]),2);;
        }
        return sqrt($d2);
}
 
 
$link = mysql_pconnect("localhost");
mysql_select_db("edited");
 
$res = mysql_query("select distinct site_id from site where is_cluster='y'",$link);
while ($tmp = mysql_fetch_row($res)) {
        $sid[] = $tmp[0];
}
 
$nsites = count($sid);
for ($i=0; $i<$nsites; $i++) {
 
        $tsid = $sid[$i];
 
        $q = "select distinct site_id,ligand_id,symbol,x,y,z ";
        $q .= " from atom where site_id='".$tsid."' and ligand_id like '%s0lm'";
 
        $res = mysql_query($q,$link);
        $natoms=0;
        while ($tmp = mysql_fetch_array($res)) {
                $atom[$natoms++] = $tmp;
        }
        
        for ($j=0; $j<$natoms; $j++) {
                for ($k=$j+1; $k<$natoms; $k++) {
                        $dist = getdist(coords($atom[$j]),coords($atom[$k]));
                        $record["source_id"] = "'".substr($atom[$j]["site_id"],0,10)."'";
                        $record["site_id"] = "'".$atom[$j]["site_id"]."'";
                        $record["ligand_id"] = "'".$atom[$j]["ligand_id"]."'";
                        $record["atom1"] = "'".$atom[$j]["symbol"]."'";
                        $record["atom2"] = "'".$atom[$k]["symbol"]."'";
                        $record["distance"] = $dist;
                        $record["timestamp"] = "'".date("YmdHis",time())."'";
                        print_array($record);
                        echo "<HR>";
                        #echo "$j $k $dist<BR><BR>\n";
                        /*
                        $inquery = "insert into cluster (source_id,site_id,ligand_id,atom1,atom2,distance,updated) ";
                        $inquery .= " values (".implode($record,",").")";
                        $inresult = mysql_query($inquery,$link);
                        if ($inresult) { echo "SUCCESS\n"; print_array($record); echo "\n\n"; }
                        */
                }
        }
 
}
 
 
?>

The tables were generated by using:

# site table

CREATE TABLE site (
  source_id varchar(25) DEFAULT '' NOT NULL,
  site_id varchar(25) DEFAULT '' NOT NULL,
  metal char(2) DEFAULT '' NOT NULL,
  metal_chain char(1),
  is_cluster enum('n','y') DEFAULT 'n' NOT NULL,
  geometry_id smallint(5) unsigned DEFAULT '0' NOT NULL,
  class_id smallint(5) unsigned DEFAULT '0' NOT NULL,
  function_id smallint(5) unsigned DEFAULT '0' NOT NULL,
  nligands_s1 smallint(5) unsigned DEFAULT '0' NOT NULL,
  nlig_protein smallint(5) unsigned,
  nlig_nucleic smallint(5) unsigned,
  nlig_metal smallint(5) unsigned,
  nlig_water smallint(5) unsigned,
  nlig_anion smallint(5) unsigned,
  nlig_hetero smallint(5) unsigned,
  nligands_s2 smallint(5) unsigned DEFAULT '0' NOT NULL,
  apo_site enum('n','y') DEFAULT 'n' NOT NULL,
  repr_phom enum('n','y') DEFAULT 'n' NOT NULL,
  repr_lhom enum('n','y') DEFAULT 'n' NOT NULL,
  repr_mdl enum('n','y') DEFAULT 'n' NOT NULL,
  repr_chn enum('n','y') DEFAULT 'n' NOT NULL,
  public enum('y','n') DEFAULT 'y' NOT NULL,
  updated date DEFAULT '0000-00-00' NOT NULL,
  stamp timestamp(14),
  UNIQUE site_id_IDX (site_id),
  KEY metal_IDX (metal),
  KEY is_cluster_IDX (is_cluster),
  KEY apo_site_IDX (apo_site),
  KEY repr_phom_IDX (repr_phom),
  KEY repr_lhom_IDX (repr_lhom),
  KEY repr_mdl_IDX (repr_mdl),
  KEY repr_chn_IDX (repr_chn),
  KEY public_IDX (public),
  KEY updated_IDX (updated),
  KEY source_id_IDX (source_id),
  KEY geometry_IDX (geometry_id),
  KEY class_IDX (class_id),
  KEY function_IDX (function_id),
  KEY nligands_s1_IDX (nligands_s1),
  KEY nligands_s2_IDX (nligands_s2)
);
 
#
# Dumping data for table 'site'
# WHERE:  is_cluster='y'
#
 
INSERT INTO site VALUES ('1frd','pdb-1frd-_-fe-1','fe','_','y',3,6,3,4,4,0,0,0,0,0,12,'n','n','y','y','y','y','1999-0
6-14',19990614172137);
INSERT INTO site VALUES ('1isu','pdb-1isu-a-fe-1','fe','a','y',9,6,1,4,4,0,0,0,0,0,20,'n','n','y','y','y','y','1999-0
6-15',19990615163310);
INSERT INTO site VALUES ('1isu','pdb-1isu-b-fe-2','fe','b','y',9,6,3,4,4,0,0,0,0,0,20,'n','n','n','n','n','y','1999-0
6-15',19990615180406);


# atom table

CREATE TABLE atom (
  site_id varchar(25) DEFAULT '' NOT NULL,
  ligand_id varchar(30) DEFAULT '' NOT NULL,
  symbol varchar(4) DEFAULT '' NOT NULL,
  seqnum smallint(5) unsigned DEFAULT '0' NOT NULL,
  x double(16,4),
  y double(16,4),
  z double(16,4),
  public enum('y','n') DEFAULT 'y' NOT NULL,
  updated date DEFAULT '0000-00-00' NOT NULL,
  stamp varchar(16) DEFAULT '' NOT NULL,
  KEY site_id_IDX (site_id),
  KEY ligand_id_IDX (ligand_id),
  KEY updated_IDX (updated),
  KEY public_IDX (public),
  KEY symbol_IDX (symbol),
  UNIQUE atom_IDX (ligand_id,symbol,seqnum,stamp,updated)
);
 
#
# Dumping data for table 'atom'
# WHERE:  ligand_id like '%s0lm'
#
 
INSERT INTO atom VALUES ('pdb-1irn-_-zn-1','pdb-1irn-_-zn-1-s0lm','zn',765,14.0030,26.0880,26.7150,'y','1999-06-02','
19990602112833');
INSERT INTO atom VALUES ('pdb-1plc-_-cu-1','pdb-1plc-_-cu-1-s0lm','cu',1548,7.0500,34.9600,18.7160,'y','1999-05-28','
19990528172159');
INSERT INTO atom VALUES ('pdb-1hca-_-zn-1','pdb-1hca-_-zn-1-s0lm','zn',2041,-6.6820,-1.5410,15.5630,'y','1999-06-04',
'19990604160830');
INSERT INTO atom VALUES ('pdb-1a4f-a-fe-1','pdb-1a4f-a-fe-1-s0lm','fe',1088,36.6930,17.5480,40.5390,'y','1999-06-08',
'19990608175706');
INSERT INTO atom VALUES ('pdb-1a4f-b-fe-2','pdb-1a4f-b-fe-2-s0lm','fe',2298,57.3420,-4.1540,22.3410,'y','1999-06-08',
'19990608182856');
INSERT INTO atom VALUES ('pdb-1cll-_-ca-1','pdb-1cll-_-ca-1-s0lm','ca',1135,1.7080,47.7760,24.1970,'y','1999-06-09','
19990609183020');
INSERT INTO atom VALUES ('pdb-1cll-_-ca-2','pdb-1cll-_-ca-2-s0lm','ca',1136,-2.1120,44.4380,13.3600,'y','1999-06-09',
'19990609185216');
INSERT INTO atom VALUES ('pdb-1cll-_-ca-3','pdb-1cll-_-ca-3-s0lm','ca',1137,30.4630,11.9620,10.4730,'y','1999-06-09',
'19990609201249');
INSERT INTO atom VALUES ('pdb-1cll-_-ca-4','pdb-1cll-_-ca-4-s0lm','ca',1138,29.1810,17.9630,0.8040,'y','1999-06-09','
19990609203451');
INSERT INTO atom VALUES ('pdb-1bbh-a-fe-1','pdb-1bbh-a-fe-1-s0lm','fe',969,24.3940,44.9620,56.8930,'y','1999-06-10','
19990610184224');
INSERT INTO atom VALUES ('pdb-1bbh-b-fe-2','pdb-1bbh-b-fe-2-s0lm','fe',1980,37.0350,25.2340,55.6390,'y','1999-06-10',
'19990610193726');
INSERT INTO atom VALUES ('pdb-1frd-_-fe-1','pdb-1frd-_-fe-1-s0lm','fe1',757,3.4280,22.1610,1.7620,'y','1999-06-14','1
9990614172137');
INSERT INTO atom VALUES ('pdb-1frd-_-fe-1','pdb-1frd-_-fe-1-s0lm','fe2',758,1.2700,22.9730,0.3620,'y','1999-06-14','1
9990614172137');
INSERT INTO atom VALUES ('pdb-1frd-_-fe-1','pdb-1frd-_-fe-1-s0lm','s1',759,1.7750,20.9300,0.9750,'y','1999-06-14','19
990614172137');
INSERT INTO atom VALUES ('pdb-1frd-_-fe-1','pdb-1frd-_-fe-1-s0lm','s2',760,2.9810,24.1680,1.0630,'y','1999-06-14','19
990614172137');
INSERT INTO atom VALUES ('pdb-1isu-a-fe-1','pdb-1isu-a-fe-1-s0lm','fe1',441,35.5410,37.8190,3.7680,'y','1999-06-15','
19990615163310');
INSERT INTO atom VALUES ('pdb-1isu-a-fe-1','pdb-1isu-a-fe-1-s0lm','fe2',442,33.2720,38.6400,2.4290,'y','1999-06-15','
19990615163310');
INSERT INTO atom VALUES ('pdb-1isu-a-fe-1','pdb-1isu-a-fe-1-s0lm','fe3',443,33.5850,36.0200,3.1800,'y','1999-06-15','
19990615163310');
INSERT INTO atom VALUES ('pdb-1isu-a-fe-1','pdb-1isu-a-fe-1-s0lm','fe4',444,35.1090,36.9990,1.2420,'y','1999-06-15','
19990615163310');
INSERT INTO atom VALUES ('pdb-1isu-a-fe-1','pdb-1isu-a-fe-1-s0lm','s1',445,35.4500,39.2150,1.9240,'y','1999-06-15','1
9990615163310');
INSERT INTO atom VALUES ('pdb-1isu-a-fe-1','pdb-1isu-a-fe-1-s0lm','s2',446,33.4060,37.8500,4.5610,'y','1999-06-15','1
9990615163310');
INSERT INTO atom VALUES ('pdb-1isu-a-fe-1','pdb-1isu-a-fe-1-s0lm','s3',447,35.8210,35.8010,3.0380,'y','1999-06-15','1
9990615163310');
INSERT INTO atom VALUES ('pdb-1isu-a-fe-1','pdb-1isu-a-fe-1-s0lm','s4',448,32.8460,36.9190,1.1640,'y','1999-06-15','1
9990615163310');
INSERT INTO atom VALUES ('pdb-1isu-b-fe-2','pdb-1isu-b-fe-2-s0lm','fe1',889,20.5550,33.0360,20.7290,'y','1999-06-15',
'19990615180406');
INSERT INTO atom VALUES ('pdb-1isu-b-fe-2','pdb-1isu-b-fe-2-s0lm','fe2',890,21.9130,34.9750,22.1450,'y','1999-06-15',
'19990615180406');
INSERT INTO atom VALUES ('pdb-1isu-b-fe-2','pdb-1isu-b-fe-2-s0lm','fe3',891,23.3020,33.2740,20.4850,'y','1999-06-15',
'19990615180406');
INSERT INTO atom VALUES ('pdb-1isu-b-fe-2','pdb-1isu-b-fe-2-s0lm','fe4',892,22.1510,32.3330,22.7630,'y','1999-06-15',
'19990615180406');
INSERT INTO atom VALUES ('pdb-1isu-b-fe-2','pdb-1isu-b-fe-2-s0lm','s1',893,20.2360,33.6320,22.9280,'y','1999-06-15','
19990615180406');
INSERT INTO atom VALUES ('pdb-1isu-b-fe-2','pdb-1isu-b-fe-2-s0lm','s2',894,21.7370,34.8250,19.8220,'y','1999-06-15','
19990615180406');
INSERT INTO atom VALUES ('pdb-1isu-b-fe-2','pdb-1isu-b-fe-2-s0lm','s3',895,21.9910,31.4430,20.7040,'y','1999-06-15','
19990615180406');
INSERT INTO atom VALUES ('pdb-1isu-b-fe-2','pdb-1isu-b-fe-2-s0lm','s4',896,23.8310,33.9820,22.7210,'y','1999-06-15','
19990615180406');

# cluster table (populated by the script cluster.php3)
CREATE TABLE cluster (
  source_id varchar(20) DEFAULT '' NOT NULL,
  site_id varchar(20) DEFAULT '' NOT NULL,
  ligand_id varchar(30) DEFAULT '' NOT NULL,
  atom1 varchar(5) DEFAULT '' NOT NULL,
  atom2 varchar(5) DEFAULT '' NOT NULL,
  distance float(10,2) unsigned DEFAULT '0.00' NOT NULL,
  updated timestamp(14),
  KEY source_id (source_id),
  KEY site_id (site_id),
  KEY ligand_id (ligand_id),
  KEY atom1 (atom1),
  KEY atom2 (atom2)
);

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [1999-06-23 16:53 UTC] jesusmc at scripps dot edu
Here is the backtrace using the PHP 3.0.9 stand alone.

GNU gdb 4.17
Copyright 1998 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for details.
This GDB was configured as "sparc-sun-solaris2.5.1"...
Core was generated by `php309 clu2.php3'.
Program terminated with signal 10, Bus Error.
Reading symbols from /home/jesusmc/devel/mysql/lib/mysql/libmysqlclient.so.6...done.
Reading symbols from /asd/dredox3/development/pgsql/lib//libpq.so...done.
Reading symbols from /opt/SUNWspro/lib/libm.so.1...done.
Reading symbols from /usr/lib/libdl.so.1...done.
Reading symbols from /usr/lib/libsocket.so.1...done.
Reading symbols from /usr/lib/libnsl.so.1...done.
Reading symbols from /usr/lib/libresolv.so.1...done.
Reading symbols from /usr/lib/libc.so.1...done.
Reading symbols from /usr/ucblib/libucb.so.1...done.
Reading symbols from /usr/lib/libelf.so.1...done.
Reading symbols from /usr/lib/libintl.so.1...done.
Reading symbols from /usr/lib/libmp.so.1...done.
Reading symbols from /usr/lib/libw.so.1...done.
Reading symbols from /usr/platform/SUNW,Ultra-1/lib/libc_psr.so.1...done.
Reading symbols from /usr/lib/nss_files.so.1...done.
Reading symbols from /usr/lib/nss_nis.so.1...done.
#0  0x6fd4b180 in _smalloc ()
(gdb) bt
#0  0x6fd4b180 in _smalloc ()
#1  0x6fd4b1c4 in malloc ()
#2  0x375b4 in _emalloc (size=2) at alloc.c:115
#3  0x2f18c in _php3_hash_add_or_update (ht=0x173ab0, arKey=0x173298 "z", nKeyLength=2, 
    pData=0xefffdd60, nDataSize=16, pDest=0x0, flag=0) at php3_hash.c:187
#4  0x301b8 in _php3_hash_copy (target=0xefffdec0, source=0x172a40, 
    pCopyConstructor=0x32d08 <pval_copy_constructor>, tmp=0xefffdd60, size=16)
    at php3_hash.c:715
#5  0x32dd0 in pval_copy_constructor (pvalue=0xefffdeb8) at variables.c:139
#6  0x214d0 in phpparse () at control_structures_inline.h:436
#7  0x2e540 in php3_parse (yyin=0x107800) at main.c:1541
#8  0x2edcc in main (argc=2, argv=0xefffeea4) at main.c:1850
(gdb)
 [2002-06-16 08:32 UTC] sander@php.net
Thank you for taking the time to report a problem with PHP.
Unfortunately, PHP 3 is no longer supported. Please download
the latest version of PHP 4 from http://www.php.net/downloads.php

If you are able to reproduce the bug with one of the latest
versions of PHP, please change the PHP version on this bug report
to the version you tested and change the status back to "Open".
Again, thank you for your continued support of PHP.
 
PHP Copyright © 2001-2017 The PHP Group
All rights reserved.
Last updated: Sun Nov 19 01:31:42 2017 UTC