Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:57237 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 55887 invoked from network); 5 Jan 2012 10:58:21 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 5 Jan 2012 10:58:21 -0000 Authentication-Results: pb1.pair.com smtp.mail=laruence@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=laruence@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.212.42 as permitted sender) X-PHP-List-Original-Sender: laruence@gmail.com X-Host-Fingerprint: 209.85.212.42 mail-vw0-f42.google.com Received: from [209.85.212.42] ([209.85.212.42:40905] helo=mail-vw0-f42.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id E5/3A-28877-C42850F4 for ; Thu, 05 Jan 2012 05:58:20 -0500 Received: by vbbfd1 with SMTP id fd1so296795vbb.29 for ; Thu, 05 Jan 2012 02:58:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:sender:in-reply-to:references:from:date :x-google-sender-auth:message-id:subject:to:cc:content-type :content-transfer-encoding; bh=a37WbqaEqqnCVoHLmlEDrWDYeYcqRTLShmTEAl+waRo=; b=WzVoEvhhh7IxEfGpAvw7pBnjqoyuRxsVnAtIZS+/5YvR1btpv5MdFcbqJve5Y2j4w9 msuDp3Zrc1rWIS7+TD7UiGTFW3CgapJ4PL3LOYuvwVIXfbHgmEeYENexIecrnM11G5NI pEOr9hADylHLmiprnMC7rRhuArDDDav9vKKcQ= Received: by 10.52.26.199 with SMTP id n7mr744708vdg.17.1325761097310; Thu, 05 Jan 2012 02:58:17 -0800 (PST) MIME-Version: 1.0 Sender: laruence@gmail.com Received: by 10.220.3.14 with HTTP; Thu, 5 Jan 2012 02:57:56 -0800 (PST) In-Reply-To: References: Date: Thu, 5 Jan 2012 18:57:56 +0800 X-Google-Sender-Auth: 8eMsycADsomI1wbyRmAordGGP7w Message-ID: To: PHP Internals Cc: Rasmus Lerdorf , Stas Malyshev , Pierre Joye , =?UTF-8?Q?Johannes_Schl=C3=BCter?= , Dmitry Stogov Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: Re: Yet another fix for max_input_vars From: laruence@php.net (Laruence) Hi: run bench.php: *before patched: $ sapi/cli/php Zend/bench.php simple 0.374 simplecall 0.720 simpleucall 0.600 simpleudcall 0.633 mandel 1.161 mandel2 1.632 ackermann(7) 0.810 ary(50000) 0.108 ary2(50000) 0.098 ary3(2000) 0.699 fibo(30) 2.180 hash1(50000) 0.168 hash2(500) 0.171 heapsort(20000) 0.395 matrix(20) 0.354 nestedloop(12) 0.656 sieve(30) 0.441 strcat(200000) 0.073 ------------------------ Total 11.276 *after patched: sapi/cli/php Zend/bench.php simple 0.520 simplecall 0.723 simpleucall 0.622 simpleudcall 0.639 mandel 1.168 mandel2 1.711 ackermann(7) 0.784 ary(50000) 0.116 ary2(50000) 0.100 ary3(2000) 0.749 fibo(30) 2.188 hash1(50000) 0.177 hash2(500) 0.184 heapsort(20000) 0.421 matrix(20) 0.420 nestedloop(12) 0.836 sieve(30) 0.458 strcat(200000) 0.073 ------------------------ Total 11.888 thanks On Thu, Jan 5, 2012 at 4:53 PM, Laruence wrote: > Hi: > =C2=A0 =C2=A0the origin thread is too long, so I open a new thread for th= is. > > =C2=A0 =C2=A0I have made another patch try to fix this issue. > > =C2=A0 =C2=A0the key point is, randomizing the table size(tableMask). > > =C2=A0 =C2=A0instead of double the the table size in zend_hash_do_resize,= =C2=A0I > increase the table size with a random delta ( the value now is just a > try, =C2=A0we can change it to a more appropriate value), > =C2=A0that is: =C2=A0new_table_size =3D old_table_size * 2 + random_num. > > =C2=A0 =C2=A0then, =C2=A0the collision can not be predicatible, which fix= the > problem, =C2=A0and also fixed the issue in json/soap/serialize etc. > > =C2=A0 =C2=A0here is the patch(draft now): > https://bugs.php.net/patch-display.php?bug_id=3D60655&patch=3Drand_hash_r= esize.patch&revision=3Dlatest > > =C2=A0 =C2=A0after this fix , may slow down the php, but compared to the > security threat I thinks the cost could be ignored. > > =C2=A0 =C2=A0for the test script list in > http://nikic.github.com/2011/12/28/Supercolliding-a-PHP-array.html: > > =C2=A0 =C2=A0*before patched: > =C2=A0 =C2=A0 =C2=A0 =C2=A0Inserting 65536 evil elements took 162.6594028= 4729 seconds > =C2=A0 =C2=A0 =C2=A0 =C2=A0Inserting 65536 good elements took 0.075557947= 158813 seconds > > =C2=A0 =C2=A0*after =C2=A0patched: > =C2=A0 =C2=A0 =C2=A0 =C2=A0Inserting 65536 evil elements took 0.074128866= 195679 seconds > =C2=A0 =C2=A0 =C2=A0 =C2=A0Inserting 65536 good elements took 0.091044902= 801514 seconds > > =C2=A0 =C2=A0what do you think ? > > thanks > > -- > Laruence =C2=A0Xinchen Hui > http://www.laruence.com/ --=20 Laruence =C2=A0Xinchen Hui http://www.laruence.com/