Debian Bug report logs - #245934
php4: array_walk() crashes

version graph

Package: php4; Maintainer for php4 is (unknown);

Reported by: Paul Slootman <paul@debian.org>

Date: Mon, 26 Apr 2004 09:33:06 UTC

Severity: important

Found in version 4:4.3.3-4

Done: Ondrej Sury <ondrej@sury.org>

Bug is archived. No further changes may be made.

Toggle useless messages

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to debian-bugs-dist@lists.debian.org, Adam Conrad <adconrad@0c3.net>:
Bug#245934; Package php4. Full text and rfc822 format available.

Acknowledgement sent to Paul Slootman <paul@debian.org>:
New Bug report received and forwarded. Copy sent to Adam Conrad <adconrad@0c3.net>. Full text and rfc822 format available.

Message #5 received at submit@bugs.debian.org (full text, mbox):

From: Paul Slootman <paul@debian.org>
To: Debian Bug Tracking System <submit@bugs.debian.org>
Subject: php4: array_walk() crashes
Date: Mon, 26 Apr 2004 11:28:06 +0200
Package: php4
Version: 4:4.3.3-4
Severity: important

When trying to dump an array structure to a format suitable for
generating XML (there aren't any PHP modules for generating XML that I
could find, only for parsing XML), I found that php was crashing after I
had extended the array a bit.

I use array_walk() recursively, to a max depth of about 6.
Any self-respecting programming language should be able to handle that
:-)  Below is a script that contains the core of what I was doing, and
that shows the crash. Note that that script is more suited to running
with the php4-cgi php4 executable (which also shows the problem).

I found some vague references that php4 doesn't support recursion,
however I can't find any evidence of this in the manual. If it indeed
doesn't support recursion, perhaps that should be told explicitly in the
array_walk() manual entry. The online annotated manual page actually has
plentiful user examples of recursion...

Paul Slootman

-- System Information:
Debian Release: testing/unstable
Architecture: i386
Kernel: Linux wurtel 2.6.5-rc2 #1 Sat Mar 20 14:10:58 CET 2004 i686
Locale: LANG=C, LC_CTYPE=C

Versions of packages php4 depends on:
ii  apache-common               1.3.29.0.1-3 Support files for all Apache webse
ii  debconf                     1.4.22       Debian configuration management sy
ii  libbz2-1.0                  1.0.2-1      A high-quality block-sorting file 
ii  libc6                       2.3.2.ds1-11 GNU C Library: Shared libraries an
ii  libdb4.1                    4.1.25-10    Berkeley v4.1 Database Libraries [
ii  libexpat1                   1.95.6-6     XML parsing C library - runtime li
ii  libmm13                     1.3.0-1      Shared memory library - runtime
ii  libpam0g                    0.76-14.1    Pluggable Authentication Modules l
ii  libpcre3                    4.5-1.1      Perl 5 Compatible Regular Expressi
ii  mime-support                3.23-1       MIME files 'mime.types' & 'mailcap
ii  zlib1g                      1:1.2.1-4    compression library - runtime


<?php

    $order = array(
        "DocID"			=>	"1",
        "DocDate"		=>	date("d.m.y"),
        "ReSubmissionDate"	=>	"",
        "DocTyp"		=>	"Stapelauftrag",
        "CustID"		=>	"00000",
        "CustomerAddress" => array(
            array(
                "Name1"		=>	'name1',
                "Name2"		=>	'name2',
                "Name3"		=>	"",
                "City"		=>	'city',
                "Street"	=>	'street',
                "Postal"	=>	'postcode',
                "IATA"		=>	"90",
                "Country"	=>	"Deutschland",
                "ShortName"	=>	'short',
                "ContactKey"	=>	"",
                "EMail"		=>	'email@example.com',
            )
        ),
        "Text1"			=>	"",
        "Text2"			=>	"",
        "Wildcard1"		=>	"",
        "Wildcard2"		=>	"",
        "Dispatch"		=>	"Paketdienst",
        "Weight"		=>	"0,0",
        "BillingCustID"		=>	"4300200000",
        "ExtDocNr"		=>	"00000000003",
        "AnalysisLock"		=>	"",
        "PrintFlag"		=>	"",
        "FormType"		=>	"0",
        "Curr"			=>	"EUR",
        "ExChangeRate"		=>	"1,0000",
        "WIRRate"		=>	"0",
        "OneTimeCustomer" => array(
            array(
                "BankCode"	=>	"",
                "BankAccount"	=>	""
            )
        ),
        "Language"		=>	"0",
        "PriceGroup"		=>	"1",
        "PrFlag"		=>	"0",
        "SalesTaxKey"		=>	"1",
        "ProceedKey"		=>	"0",
        "CustDiscountGroup"	=>	"0",
        "Discount" => array(
            array(
                "FinDisc1"	=>	"0,00",
                "Disc1Base"	=>	"145,72",
                "Disc1Value"	=>	"0,00",
                "FinDisc2"	=>	"0,00",
                "Disc2Base"	=>	"145,72",
                "Disc2Value"	=>	"0,00",
                "FinDisc3"	=>	"0,00",
                "Disc3Base"	=>	"145,72",
                "Disc3Value"	=>	"0,00",
                "ValueSummary"	=>	"0,00"
            )
        ),
        "Contact" => array(
            array(
                "Repr"		=>	"999",
                "Region"	=>	"99",
                "Commission"	=>	"0,00",
                "Agent"		=>	"000000"
            )
        ),
        "Booking" => array(
            array(
                "CostUnit"	=>	"0000000000",
                "CostCentre"	=>	"0000000000",
                "AccountingArea"=>	"01"
            )
        ),
        "InvoiceCycleKey"	=>	"0",
        "AnalysisKey"		=>	"",
        "OrderNumber"		=>	"",
        "OrderDate"		=>	"",
        "OrderCode"		=>	"",
        "DocItems" => array(
            "DocItem" => array(
                "PosType"		=>	"1",
                "ItemRef"		=>	"ÚÚÚÚÚÚÚÚÚÚÚÚÚÚÚÚ1002",
                "CRef"			=>	"",
                "Desc1"			=>	"Präsentation Niederlande per",
                "Desc2"			=>	"",
                "ArticleGroup"		=>	"102",
                "PosTypeVersion"	=>	"E",
                "Delivery" => array(
                    array(
                        "DelWeek"	=>	"",
                        "DelDay"	=>	"",
                        "DelTime"	=>	""
                    )
                ),
        "PricePu"		=>	"145,72",
        "PriceUnit"		=>	"0",
        "PriceCalculation"	=>	"0",
        "ItemVal"		=>	"145,72",
        "InputKey"		=>	"0",
        "AveragePurchasePrice"	=>	"0",
                "Tax" => array(
                    array(
                        "TaxCode"	=>	"00",
                        "TaxBra"	=>	"000",
                        "TaxBraAccess"	=>	"0",
                        "TaxSumIndex"	=>	"0"
                    )
                ),
                "DiscountArticle" => array(
                    array(
                        "DiscPC"	=>	"0,00",
                        "DiscKey"	=>	"1"
                    )
                ),
                "ProceedKeyArticle"	=>	"01",
                "ActionKey"		=>	"00",
                "ContactCommissionArticle"=>	"0,00",
                "QuantDependantPriceKey"=>	"",
                "Quant"			=>	"1",
                "QuantUnit"		=>	"",
                "Meas" => array(
                    array(
                        "Count"		=>	"1",
                        "Length"	=>	"0,000",
                        "Width"		=>	"0,000",
                        "Height"	=>	"0,000"
                    )
                ),
                "DecimalPlace"		=>	"0",
                "MultiplierQuant"	=>	"1,000000",
                "DifferingQuantUnit"	=>	"",
                "DecimalPlaceConversion"=>	"0",
                "WeightArticle" => array(
                    array(
                        "Amount"	=>	"0",
                        "Unit"		=>	"0"
                    )
                ),
                "Wreath"		=>	"0,000",
                "Stock"			=>	"1",
                "CostUnitArticle"	=>	"",
                "SerialNbKey"		=>	"0",
                "TextComplementKey"	=>	"0",
                "PartsListPrintKey"	=>	"",
                "Prod"			=>	"0000000000"
            )
        ),
        "Payment" => array(
            "PaymentKey"		=>	"0",
            "ReminderKey"		=>	"00",
            "PayTerms" => array(
                array(
                    "PayTerm"		=>	"1",
                    "PayDays"		=>	"000",
                    "CashDiscDays1"	=>	"000",
                    "CashDiscDays2"	=>	"000",
                    "CashDiscPer1"	=>	"0,00",
                    "CashDiscPer2"	=>	"0,00"
                ),
                array(
                    "PayTerm"		=>	"2",
                    "PayDays"		=>	"000",
                    "CashDiscDays1"	=>	"000",
                    "CashDiscDays2"	=>	"000",
                    "CashDiscPer1"	=>	"0,00",
                    "CashDiscPer2"	=>	"0,00"
                )
            )
        ),
        "NetAmountByTurnOverTax" => array(
            array(
                "TurnOverTaxFree"	=>	"145,72",
                "TurnOverTax1"		=>	"0,00",
                "TurnOverTax2"		=>	"0,00",
                "TurnOverTax3"		=>	"0,00",
                "TurnOverTax4"		=>	"0,00",
                "TurnOverTax5"		=>	"0,00",
                "TurnOverTax6"		=>	"0,00",
                "TurnOverTax7"		=>	"0,00",
                "TurnOverTax8"		=>	"0,00"
            ),
        ),
        "GrossAmount"			=>	"145,72",
        "ProceedAmount"			=>	"145,72",
        "NetAmountByPayTerm2" => array(
            array(
                "Sum0"			=>	"0,00",
                "Sum1"			=>	"0,00",
                "Sum2"			=>	"0,00",
                "Sum3"			=>	"0,00",
                "Sum4"			=>	"0,00",
                "Sum5"			=>	"0,00",
                "Sum6"			=>	"0,00",
                "Sum7"			=>	"0,00",
                "Sum8"			=>	"0,00"
            ),
        ),
        "TaxCodes" => array(
            array(
                "TaxCode1"		=>	"0",
                "TaxCode2"		=>	"0",
                "TaxCode3"		=>	"0",
                "TaxCode4"		=>	"0",
                "TaxCode5"		=>	"0",
                "TaxCode6"		=>	"0",
                "TaxCode7"		=>	"0",
                "TaxCode8"		=>	"0"
            )
        )
    );
    $docs = array(
        array(
            "Version"			=>	"1.0",
            "ProducerName"			=>	"xxxxxxxx",
            "ProductName"			=>	"Classic Line",
            "xmlns"				=>	"x-schema:CL310_DezABFSchema.XML"
        ),
        "Company" => array(
            array(
                "MandateNumber"		=>	"111",
                "MandateName"  		=>	"xxx xxxxxxx-xxxxx xxxxxxx",
                "MandateCurr"  		=>	"EUR"
            ),
        ),
        "Doc" => $order
    );

    dump2xml($docs);


function dump2xml($array) {
    // output of this goes through 2xml
    array_walk(&$array, "gen_xml", "/Docs/");
}
function gen_xml($val, $key, $prefix)
{
    global $xml_fd;
    print "gen_xml(prefix=$prefix)\n";
    if (is_array($val)) {
	if (preg_match('/^\d+$/', $key)) {
	    if ($key == 1) {
		print substr($prefix, 0, $x-1) . "\n";
	    }
	    array_walk(&$val, "gen_xml", "$prefix@");
	}
	else {
	    array_walk(&$val, "gen_xml", "$prefix$key/");
	}
    }
    else {
	    if (strlen($val) > 0)
		print "$prefix$key=$val\n";
	    else
		print "$prefix$key\n";
    }
    print "gen_xml(prefix=$prefix) end\n";
}
?>




Bug 245934 cloned as bug 322347. Request was from Ondrej Sury <ondrej@sury.org> to control@bugs.debian.org. Full text and rfc822 format available.

Reply sent to Ondrej Sury <ondrej@sury.org>:
You have taken responsibility. Full text and rfc822 format available.

Notification sent to Paul Slootman <paul@debian.org>:
Bug acknowledged by developer. Full text and rfc822 format available.

Message #12 received at 245934-done@bugs.debian.org (full text, mbox):

From: Ondrej Sury <ondrej@sury.org>
To: 245934-done@bugs.debian.org
Subject: recursive array_walk ends with correct message
Date: Wed, 10 Aug 2005 12:17:51 +0200
php4 4.4.0-1 gives following error message when I try to run your
script:

Fatal error: Allowed memory size of 8388608 bytes exhausted (tried to
allocate 138060825 bytes) in /tmp/bug.php on line 252

Which is IMHO correct behaviour.  Feel free to reopen this bug if you
have some arguments.

This bug still applies to php5 which gives Segmentation fault.

Ondrej.
-- 
Ondrej Sury <ondrej@sury.org>




Bug archived. Request was from Debbugs Internal Request <owner@bugs.debian.org> to internal_control@bugs.debian.org. (Mon, 18 Jun 2007 00:03:27 GMT) Full text and rfc822 format available.

Send a report that this bug log contains spam.


Debian bug tracking system administrator <owner@bugs.debian.org>. Last modified: Sat Apr 19 10:43:30 2014; Machine Name: beach.debian.org

Debian Bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.