Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:118779 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 25259 invoked from network); 7 Oct 2022 15:08:55 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 7 Oct 2022 15:08:55 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 62F491804AC for ; Fri, 7 Oct 2022 08:08:54 -0700 (PDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,NICE_REPLY_A, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS15169 209.85.128.0/17 X-Spam-Virus: No X-Envelope-From: Received: from mail-wm1-f48.google.com (mail-wm1-f48.google.com [209.85.128.48]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Fri, 7 Oct 2022 08:08:53 -0700 (PDT) Received: by mail-wm1-f48.google.com with SMTP id bg9-20020a05600c3c8900b003bf249616b0so2767220wmb.3 for ; Fri, 07 Oct 2022 08:08:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=YQ4RzBPZya4yu5SLxJa9ZQ8OPgbuHuJIg7JPJGgPQJY=; b=hhRpJb78rcSvUOefQn0s7Dnj6rJFQu1ncT/Ll9DauvZUSuUd28pIUFGcDVRBT5otIp 6C2w4b3KqT5eAxd7m7wiWsXURfTjSBM1lxfgtwJHc3U1mRzMo6buB7AcplSxm+MmXUcP Yl76Er6aJXwsDZbEYyUAE9JfzyAiMb4rQJfbhp0iw8CNVaEhcWZ2QfcfI5i3rkVtrxfb +70Ov/z6llSniNzn/VGcm9FaQOb+DcehR0sXuhaW8WVxKaRZc6D5guWoyMFl/3mI3Oxv wtyQBW2RACEOwqrYJFPOtznBrcmjbe1kwCeITmIOqtijoERRfMB2YiTH7lTvjcZ3lvYm AxyA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=YQ4RzBPZya4yu5SLxJa9ZQ8OPgbuHuJIg7JPJGgPQJY=; b=Y8MxIGnNk34q3xthyo11IKFgsyAB+JUeQCIo1jGZqI4PNktxzbzLTzLBnd914RQFsP 09bET44r10qK60sYk5RwY2KXwT+sNVhUUeR2hg/vu3AEfc8nfBYAgT116q0gnV16Vfle 89+j4n2AwXz2Sn5UbWPSxn0AcgQPVgMype5eXQ+al/2y7BBSighyC1pcF1gYBIycsS7d 5EIIpSQ87412NuIndkNHRz8lue8igZ6qraqh6QiUFMS/EuFskHKpmOJ0ZWxL5cUAGbly OUYykK1J8iocvkMAiwr5pnx3gG7OzcLGlwcliGHNCGI+tjicSUVwXxs5ROqpVRf6dq43 kNVA== X-Gm-Message-State: ACrzQf0nX10MVxZp9oU/4/w9EZPGFof2ByKFxmoW08i7AYMQxk13fhMj nvSf1kTc7Cx3e+gzGaMB2ZyQ3xEFmsuU8A== X-Google-Smtp-Source: AMsMyM7sD2YjyIE/i2Jpa6k2LikcbIa5xmj+h4n/sayUR6yH+CwbWXO6SJKRnDYd2RcplaU/8nZVgQ== X-Received: by 2002:a05:600c:46c6:b0:3b4:cad4:7d3e with SMTP id q6-20020a05600c46c600b003b4cad47d3emr10901476wmo.78.1665155332509; Fri, 07 Oct 2022 08:08:52 -0700 (PDT) Received: from ?IPV6:2a01:cb04:4b6:6600:f8a3:746b:2868:d3a3? (2a01cb0404b66600f8a3746b2868d3a3.ipv6.abo.wanadoo.fr. [2a01:cb04:4b6:6600:f8a3:746b:2868:d3a3]) by smtp.gmail.com with ESMTPSA id e1-20020a5d5941000000b0022af865810esm2238151wri.75.2022.10.07.08.08.51 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 07 Oct 2022 08:08:51 -0700 (PDT) Message-ID: Date: Fri, 7 Oct 2022 17:08:51 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.11.0 Content-Language: en-US To: Yasuo Ohgaki Cc: PHP Internals List References: <8392afe2-3f5b-5811-64fc-a38f40f9af7a@gmail.com> In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Subject: Re: [PHP-DEV] Preventing stack overflows From: arnaud.lb@gmail.com (Arnaud Le Blanc) On 07/10/2022 16:14, Yasuo Ohgaki wrote: > The root cause that users cannot understand what happened is this: > > $ php -n -r 'set_error_handler(function ($severity,$message, $filename, > $lineno) { throw new ErrorException($message, 0, $severity, $filename, > $lineno); });  function f() { f(); } f();' > > Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to > allocate 262144 bytes) in Command line code on line 1 > > When a fatal error happens, PHP does not allow  a stack dump.  Very old > PHP allowed users to catch E_ERROR by user error handler, but it is > disabled to prevent users from shooting their own foot. > I suppose allowing users to catch "only one" fatal error would solve > many issues as  well as infinite recursion. Fatal errors definitely need improvements. Stack overflows are even worth, as the process is terminated by the system: $ php test.php Segmentation fault With the proposed change, an exception is throw before it happens: $ php test.php Fatal error: Uncaught Error: Maximum call stack size of 28672 bytes reached. Infinite recursion? in test.php:8 Stack trace: #0 test.php(8): C->__destruct() #1 test.php(8): C->__destruct() #2 test.php(8): C->__destruct() ... #7 {main} thrown in test.php on line 8