Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:87311 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 56068 invoked from network); 27 Jul 2015 06:57:50 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 27 Jul 2015 06:57:50 -0000 Authentication-Results: pb1.pair.com header.from=scott@paragonie.com; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=scott@paragonie.com; spf=permerror; sender-id=unknown Received-SPF: error (pb1.pair.com: domain paragonie.com from 209.85.192.46 cause and error) X-PHP-List-Original-Sender: scott@paragonie.com X-Host-Fingerprint: 209.85.192.46 mail-qg0-f46.google.com Received: from [209.85.192.46] ([209.85.192.46:36348] helo=mail-qg0-f46.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 09/26-06606-E66D5B55 for ; Mon, 27 Jul 2015 02:57:50 -0400 Received: by qgy5 with SMTP id 5so45559993qgy.3 for ; Sun, 26 Jul 2015 23:57:47 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:date :message-id:subject:from:to:cc:content-type :content-transfer-encoding; bh=PAHkjyD9a1rLvvB78XQllZgNyw5VyBviADkvZ0MXRP8=; b=D7Iy5xIDSS8aF6iHi0Hme8/hK4NoMlbXBjIZnBKrF76sHkHoDteU7PKuK0XhhFwMJj Kx51Jl/32JaCuaO43ns9qxVO9Crswqw/kpbp6pFOV6Ft7p4E36h/OceQzs1yPLuBdeR3 gVudzYupC6zS4Cx+Yl3bsHOljJIL1qvvGnXkWrrEkc+eaFiTp2nfF1RGi/IveDOVXwu/ NxZxodS+qVt2chf/Jd1Itfkz3SCMAw+ExOXh2lgTwgAqCzQwHGyjtv3kwF605kyjnGgM 3HuA8ggLE6sczmEseaMyuljvqLNjcG/xCnV3F7LWCsE9hCht3kY96MTOPj7wYrh7TFgM eY6w== X-Gm-Message-State: ALoCoQkSVB65PsJYGBxVq985xqQgq3WZsa/8np4yGyoOvJza+PC3AZhhbZ/axLaekJx0l0I4Yi3d MIME-Version: 1.0 X-Received: by 10.140.237.147 with SMTP id i141mr41088840qhc.25.1437980267603; Sun, 26 Jul 2015 23:57:47 -0700 (PDT) Received: by 10.96.83.102 with HTTP; Sun, 26 Jul 2015 23:57:47 -0700 (PDT) In-Reply-To: <05f101d0c838$fcdab5e0$f69021a0$@belski.net> References: <836BA21C-AE99-4E7B-AB06-EBC30E41BA0E@icicle.io> <0AD335F5-35F3-4D98-8F82-800A1EDF8FD8@icicle.io> <05f101d0c838$fcdab5e0$f69021a0$@belski.net> Date: Mon, 27 Jul 2015 02:57:47 -0400 Message-ID: To: Anatol Belski Cc: Aaron Piotrowski , Sammy Kaye Powers , Larry Garfield , =?UTF-8?B?SmFrdWIgS3Viw63EjWVr?= , Stanislav Malyshev , rowan.collins@gmail.com, Pierre Joye , Dean Eigenmann , Yasuo Ohgaki , PHP Internals Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [PHP-DEV] Core functions throwing exceptions in PHP7 From: scott@paragonie.com (Scott Arciszewski) My only concern is that, we have a fixed timetable for the 7.0.0 release. It's certainly a good idea to develop a cogent strategy before moving forward, but I worry that bikeshedding will get involved and we won't make the deadline. I propose that, if a better strategy cannot be presented in time for RC1, consistency should take a back seat to security. Fail hard, throw an Error, deal with the details later. Scott Arciszewski Chief Development Officer Paragon Initiative Enterprises On Mon, Jul 27, 2015 at 2:53 AM, Anatol Belski wrot= e: > Hi Aaron, > >> -----Original Message----- >> From: Aaron Piotrowski [mailto:aaron@icicle.io] >> Sent: Monday, July 27, 2015 5:32 AM >> To: Sammy Kaye Powers ; Scott Arciszewski >> >> Cc: Anatol Belski ; larry@garfieldtech.com; Jakub >> Kub=C3=AD=C4=8Dek ; Stanislav Malyshev >> ; scott@paragonie.com; rowan.collins@gmail.com; >> pierre.php@gmail.com; Dean Eigenmann ; >> Yasuo Ohgaki ; PHP Internals >> Subject: Re: [PHP-DEV] Core functions throwing exceptions in PHP7 >> >> >> > I must have overlooked a detail here. >> > >> > According to >> > https://github.com/tpunt/PHP7-Reference#throwable-interface >> > there are Throwables called Error, as a separate designation from an >> > exception. I didn't see this in the engine exceptions RFC, so I was >> > unaware that was even a thing. >> > >> > In this case, yes, as long as you can wrap it in try/catch blocks, >> > SecurityError which extends Error and/or implements Throwable is an >> > excellent suggestion. >> > >> > Previously, I thought the suggestion was to stick to triggering errors >> > (E_ERROR, E_RECOVERABLE_ERROR, etc.). >> > >> > Scott Arciszewski >> > Chief Development Officer >> > Paragon Initiative Enterprises >> > >> > -- >> > PHP Internals - PHP Runtime Development Mailing List To unsubscribe, >> > visit: http://www.php.net/unsub.php >> > >> >> I believe some were suggesting triggering an E_ERROR, though most E_ERRO= Rs >> in the engine have been replaced with thrown Error exceptions, so I thin= k > using >> E_ERROR in this case would be inappropriate. >> >> As I suggested in my prior email, I think throwing an instance of Error > would be >> appropriate when the functions random_bytes() and random_int() fail. >> >> There are several conditions that already cause the engine to throw an > Error (or >> subclass thereof): >> >> (1)->method(); // Throws Error >> declare(strict_types=3D1); array_map(1, 1); // Throws TypeError require > 'file-with- >> parse-error.php'; // Throws ParseError eval("$a[ =3D 1;"); // Throws > ParseError >> 1 << -1; // Throws ArithmeticError >> intdiv(1, 0); // Throws DivisionByZeroError >> 1 % 0; // Throws DivisionByZeroError >> >> Of particular interest in the above examples is intdiv(), an internal > function that >> can throw an instance of Error if the denominator is zero. >> >> I propose that random_bytes() and random_int() should throw an instance = of >> Error if the parameters are not as expected or if generating a random > number >> fails. (To avoid further debate about a subclass, the function should > throw just a >> plain instance of Error, it can always be subclassed later without BC > concerns). >> >> random_bytes() and random_int() failing closed is very important to > prevent >> misguided or lazy programmers from using false in place of a random valu= e. > A >> return of false can easily be overlooked and unintentionally be cast to = a > zero or >> empty string. A thrown instance of Error must be purposely caught and > ignored >> to produce the same behavior. As Larry pointed out, it is a very common > error >> for programmers to not do a strict check using =3D=3D=3D against false w= hen > calling >> strpos(). >> >> Does anyone have a strong objection to the above proposal? If not, then = I > think >> Sammy should update his PRs to throw an Error so they can be merged befo= re >> the next beta release. >> > Yes, there is an objection at least on my side. As we was discussing the = PR > on the github page, the primary goal of the suggestion to move the > discussion to the intarnals list was to create an approach about exceptio= ns > in functions. This seems not be the case here. It is not the question > whether exceptions should be thrown in functions - it's almost obvious th= at > they should now after it's the engine behavior. But it is a huge question= of > the consistency with anything else. That was also the reason why me and > Kalle have changed our minds about your PR converting fatals in the > functions. > > The only case where exception is thrown in a function is intdiv() now. Bu= t > also as mentioned elsewhere - it's something tightly coupled with the > behavior of div/mod in the engine. IMHO it is not building any base for > randomly adding exceptions elsewhere. Neither I don't see as a base that = the > CSPRNG functions are new. Neither the argument "we can change it later to > xyz". The main concern is still not addressed, and even wasn't started to= be > addressed. It is for nothing to have new "nice" functions with nice and > correct behavior while leaving the old "ugly" functions ugly. > > IMO we should stop building special cases and move to the conceptualizat= ion > as first. The more special cases exist, the harder it will be in the futu= re > to bring the behaviors inline without BC breaks. Till now I haven't seen > even any gentle hint about such conceptualization work going on, no RFC p= age > still exists, but it's being continued pushing on a special case. Solving= an > immediate issue might be tactically justifiable, but without a strategica= l > thinking will lead to even a bigger issue. It is not something we want to > leave behind us for the next generations. I would kindly call therefore, = to > think about this in a more global way, discuss and show at least a rough > draft about what should be done regarding the existing functions, new > functions, backward compatibility, exact warning/error types and how they > should be converted, etc. before pushing further on this case. > > Thanks > > Anatol > >