Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:66749 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 94692 invoked from network); 22 Mar 2013 09:08:33 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 22 Mar 2013 09:08:33 -0000 Authentication-Results: pb1.pair.com header.from=dmitry@zend.com; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=dmitry@zend.com; spf=unknown; sender-id=unknown Received-SPF: unknown (pb1.pair.com: domain zend.com does not designate 209.85.212.44 as permitted sender) X-PHP-List-Original-Sender: dmitry@zend.com X-Host-Fingerprint: 209.85.212.44 mail-vb0-f44.google.com Received: from [209.85.212.44] ([209.85.212.44:37969] helo=mail-vb0-f44.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id EA/D4-35504-F8F1C415 for ; Fri, 22 Mar 2013 04:08:32 -0500 Received: by mail-vb0-f44.google.com with SMTP id fr13so2559314vbb.3 for ; Fri, 22 Mar 2013 02:08:29 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=mime-version:x-received:in-reply-to:references:date:message-id :subject:from:to:cc:content-type:x-gm-message-state; bh=N2ELarCyhlBjqSNIX3NhUBbERsGSvbG9bzWeszSXYDk=; b=VjiAbFQzYYAWiHDH0F086vwxsRX/a+5D8JDTlWFTe+TsHIirwQEL4bNYYZhOTtQmmR AwAdDIlVTJ0X85k8+i47OSm3oFfRPHegRT0gIjB81ay4o2RLKKfz+Gp1tXPuFszfahdp ScwuS5p4FmoBvvvI1H5JQpE2RPTNrMzKEdY1uxuNECiu7Bhu+wP6Eu9ErqsYEp3v5Dg5 O/nO2iFYRy+dicpkRZXCDUTAJpmph1IyyLkPi8MIKLQ/HneNthlqRzkVPEJDyb69r8vN pLs8fqircUitIEWNRP/0VcODiFaGv18wqjHn7S/QdpkkZtXv9jRzQG+o5NaksfOfNprU o7gA== MIME-Version: 1.0 X-Received: by 10.52.67.3 with SMTP id j3mr943299vdt.108.1363943309383; Fri, 22 Mar 2013 02:08:29 -0700 (PDT) Received: by 10.52.70.132 with HTTP; Fri, 22 Mar 2013 02:08:29 -0700 (PDT) In-Reply-To: References: <56994bc16a23a22f5e1b71c94b792dce.squirrel@webmail.klapt.com> Date: Fri, 22 Mar 2013 13:08:29 +0400 Message-ID: To: ab@php.net Cc: internals , Rasmus Lerdorf Content-Type: multipart/alternative; boundary=20cf307cfbd6734d1704d87fccd3 X-Gm-Message-State: ALoCoQnNu7Xen9rvae65Cen85+DRnCUDOXkZlZCKAHhD2vN5iGwCNIHMEGmavoWhVbPi/ZHnv5JWhvV4PEKquxsTlsKukWVlkvFjG/6vIRfuGH4+EIieJSiMWHRQg0WUJk0xag77Td2K Subject: Re: Fix for #64450 From: dmitry@zend.com (Dmitry Stogov) --20cf307cfbd6734d1704d87fccd3 Content-Type: text/plain; charset=UTF-8 Thanks, now I understood. :) anyway I see a problem. For example on x86_64 double is not always able to keep a long number without precision lost. May be you should receive arguments as zvals and use old or new code depending on input types. BTW: I'm not sure if rand() should be fixed at all. According to http://php.net/manual/en/function.rand.php it should accept integers and return integer. Thanks. Dmitry. On Fri, Mar 22, 2013 at 12:08 PM, Anatol Belski wrote: > Dmitry, > > first of all thanks for taking a look :) > > The issue in a few words > - mt_rand reads arguments as long > - user pass a float from the userspace > - zend_parse_parameters with 'l' casts to long > > Here's the essential snippet > echo mt_rand(0,pow(10,12)); > PHP Warning: mt_rand(): max(-727379968) is smaller than min(0) > > So reading as long would probably not work, in the first place because the > input data exceeding LONG_MAX will be corrupted by the conversion. So what > I did > - read input as max precision possible, no corruption > - calculate as well with double > - return the old way int if it's in LONG_MAX range, otherwise return float > > Is there a solution I don't see (or do I get your suggestion wrong)? It's > just essential to get the input as precise as it can be across PHP. > > Besides that what could be impacts changing input arg types in this > concrete case? User probably wouldn't realize that at all. > > Thanks > > Anatol > > On Fri, March 22, 2013 07:40, Dmitry Stogov wrote: > > Hi Anatol, > > > > > > To be honest, I didn't understand all the details of the patch :) > > > > > > However, I see a problem: > > You changed the prototype of user level rand() function to receive double > > arguments instead of long. I think it's disallowed, but you may get > > arguments as longs and then convert them to double. Will it work? > > > > > > Thanks. Dmitry. > > > > > > On Thu, Mar 21, 2013 at 9:26 PM, Dmitry Stogov wrote: > > > > > >> I'll able to look only tomorrow morning. > >> > >> > >> Thanks. Dmitry. > >> > >> > >> > >> On Thu, Mar 21, 2013 at 8:46 PM, Anatol Belski wrote: > >> > >> > >>> Hi Dmitry, > >>> > >>> > >>> I developed a patch for this one > >>> https://bugs.php.net/bug.php?id=64450 . > >>> It's regarding to the long overflow in mt_rand(). The main idea is to > >>> work with the args as double internally and then return php float if > >>> it exceeds the LONG_MAX. I strived to let the old behavior to be > >>> unchanged, all the older tests pass. Please take a look. > >>> > >>> Regards > >>> > >>> > >>> Anatol > >>> > >>> > >> > >> > > > > --20cf307cfbd6734d1704d87fccd3--