Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:117663 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 1380 invoked from network); 3 May 2022 21:12:39 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 3 May 2022 21:12:39 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 1EA3A18054B for ; Tue, 3 May 2022 15:49:45 -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=-0.2 required=5.0 tests=BAYES_40,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,HTML_MESSAGE,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS2635 192.0.84.0/24 X-Spam-Virus: No X-Envelope-From: Received: from mx1.dfw.automattic.com (mx1.dfw.automattic.com [192.0.84.151]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Tue, 3 May 2022 15:49:45 -0700 (PDT) Received: from localhost (localhost.localdomain [127.0.0.1]) by mx1.dfw.automattic.com (Postfix) with ESMTP id AD1851CF0C6 for ; Tue, 3 May 2022 22:49:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=automattic.com; h=content-type:content-type:x-mailer:mime-version:message-id :subject:subject:from:from:date:date:received:received:received :received:received:received; s=automattic1; t=1651618184; bh=OE2 0LD6lbQNncN6hOdJ+BTVO0nOU7z09YNl0SJQivzQ=; b=bv+DxzycQtiRsxYE3QH 9w/rDYzQgpajUTg65h2pMTeOVAbYQ99xnSCILcQEiWSZxj9Z/oZQPfEVw+sly0iv 1Ud/CPKrrU+L3ngW1/xs4NggjJVSr9hSN5y5Uv4ONIRmlyy6p7ei5vccIntJnTbM TiadY2x9UaqARZA8OmLx37FYHO7hjg88LPfKUl29a014RBuh7mP/3Dk2AAYhCJK3 HRzHTBqbPF7dzziHuOriHD+i7Gkt+strHJvXxdygpysXbt/AbEa6EwZRo6WS6SKi r3F+jsdcjqpQ+YCa8pajaqic0SmIBSVP4yB6H1U9mJXwbzZ1IeI/R6BAk9sUf+kC Azg== X-Virus-Scanned: Debian amavisd-new at wordpress.com Received: from mx1.dfw.automattic.com ([127.0.0.1]) by localhost (mx1.dfw.automattic.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id CNCMaQB8omPQ for ; Tue, 3 May 2022 22:49:44 +0000 (UTC) Received: from smtp-gw.dca.automattic.com (smtp-gw.dca.automattic.com [192.0.97.210]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx1.dfw.automattic.com (Postfix) with ESMTPS id 537B61CE8E9 for ; Tue, 3 May 2022 22:49:44 +0000 (UTC) Authentication-Results: mail.automattic.com; dkim=pass (2048-bit key; unprotected) header.d=automattic.com header.i=@automattic.com header.b="R8ZIw2dI"; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=a8c-com.20210112.gappssmtp.com header.i=@a8c-com.20210112.gappssmtp.com header.b="2HAhbwX4"; dkim-atps=neutral Received: from smtp-gw.dca.automattic.com (localhost.localdomain [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-gw.dca.automattic.com (Postfix) with ESMTPS id EBFA4A095C for ; Tue, 3 May 2022 22:49:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=automattic.com; s=automattic1; t=1651618184; bh=OE20LD6lbQNncN6hOdJ+BTVO0nOU7z09YNl0SJQivzQ=; h=Date:From:To:Subject:From; b=R8ZIw2dIecV/wOPMCglVH89IpvOVnLqU9TRnaM1uKY3oZGV1ZiK6od3vF7QqjUpRy sUF/i0N1Av6v56z1PMoVvW+q9mN1VGtYRrqed48vB4A8oCaaBVEE+bxK+xSEdR7/FU CaPqR9hu85gREabMocPRBMWuE+oKglRzGwGX9tF0HGeu0WruA6xq5dwcOwqMATUJbD HuwrV7F4Ba3ZWfeETdvfqGkZOA+rwomM4b0pNvRuIjYC2v45jLrTUojmgPyhe6GTaa XDn6XyN+4D0tY7w99xrsRPDSBhMl+jWoLuVT9OjKnVAdX9ptMumY6EuGngJYokNgbx Rl4WQEiBmWZBQ== Received: from mail-pg1-f197.google.com (mail-pg1-f197.google.com [209.85.215.197]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-gw.dca.automattic.com (Postfix) with ESMTPS id C5079A0221 for ; Tue, 3 May 2022 22:49:43 +0000 (UTC) Received: by mail-pg1-f197.google.com with SMTP id q13-20020a638c4d000000b003821725ad66so9045984pgn.23 for ; Tue, 03 May 2022 15:49:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=a8c-com.20210112.gappssmtp.com; s=20210112; h=date:from:to:subject:message-id:mime-version; bh=ag5h/EeCpG558WyMhiJ1aqwxqqi83sSV+1HayoUD5JU=; b=2HAhbwX48W8wUHa4vlFEBq/4oYYlpn4KHC/XjeUD9N4CyAw1dmNsQOGNoPpL5PdZax afaWES3Mfg8nW+re5gopcmX6/cPM4XwbnkhH5V8MWF1BY6BBWeUDMnoSEPBUnfeeAuU0 Cf+PAWhKvMAdEhSgZdgMFK8j7DXs+gpefkqAvnliJPupOVzMh32Afy2mVryFy2senZ4K sFClcJSWvReM8vsSWa2uY+cIR+NteXlnBWoevyZLVkmHfRfsJker7fDtQAu0PKk6VZ9a HIeNTw2OhYtD8eVKDSg+iCUToTQ+GUI21I05Vv7efsrMMjvA4j4Fjt8JXX0T7c9dPLvj vZjQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:subject:message-id:mime-version; bh=ag5h/EeCpG558WyMhiJ1aqwxqqi83sSV+1HayoUD5JU=; b=4emWYdQkOQff17nGxa8LpqPtjNKEoLV+E/762XLi0xW8nZmFrdgXC6pi0W5tSQQiAP Hmw5YetqdVvZHPkjs0vNlxFRMgERenIORhw/9v1D4pzzw62GCLlMIds8AFQTKD3zpnbd RZz2yyLE1EysLSOoSJ28sDEqAeNZ9vOBKv248Xn4eaY68eBR5neE+ukLdqN1+JvhVO8E KtZ3I0W6sYua2b/MAY6Oy0psUmGJJv123DBOOAN1ThxNohUICiMPDloktMfI28vuhk6E RlMILYfGqbz7wK+8jElVhx3Q6WjoyYFQW6GOkWe2UkfSe1XsiEvfjzQtK08F5xUNPknY YGeQ== X-Gm-Message-State: AOAM5321pfMYvwhBXu5i39IL0XHSnfzVeahFQ1Qyt9hpDdjtOrr5Rhty nCPU/LLLlQnuWfzN/L+a4BUcJxp+d5pStJmB5Sxs93UiB8t/nEkElpBThErpw6HDKbJGo4q3VHi sVt514jrNk76HxtmqqA== X-Received: by 2002:a65:615a:0:b0:3a9:f4ad:68a8 with SMTP id o26-20020a65615a000000b003a9f4ad68a8mr15937299pgv.108.1651618182640; Tue, 03 May 2022 15:49:42 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxRMNUcC6/xIkKhKTl7+6vRqsppdCtc/LjkAuD0DJln5Wel68P070nE23p5gdgiGcCL8c5Buw== X-Received: by 2002:a65:615a:0:b0:3a9:f4ad:68a8 with SMTP id o26-20020a65615a000000b003a9f4ad68a8mr15937286pgv.108.1651618182293; Tue, 03 May 2022 15:49:42 -0700 (PDT) Received: from [10.0.0.29] (ip70-172-124-59.ph.ph.cox.net. [70.172.124.59]) by smtp.gmail.com with ESMTPSA id n21-20020aa78a55000000b0050dc76281c2sm6802796pfa.156.2022.05.03.15.49.40 for (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 03 May 2022 15:49:41 -0700 (PDT) Date: Tue, 03 May 2022 15:49:41 -0700 (PDT) X-Google-Original-Date: 03 May 2022 15:49:39 -0700 X-Google-Original-From: Dennis Snell To: Message-ID: <0C542CC3-6738-4A0F-94C2-482D65886C84@automattic.com> MIME-Version: 1.0 X-Mailer: Unibox (443:21.4.0) Content-Type: multipart/alternative; boundary="=_72CE8775-537C-4664-A833-AEDDE7BF79E0" Subject: [RFC] Exposed parsed value of php.ini numeric directives From: dennis.snell@automattic.com (Dennis Snell) --=_72CE8775-537C-4664-A833-AEDDE7BF79E0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Hello all, While working on some issues in WordPress relating to displaying the config= ured max upload and POST sizes I came to realize that PHP doesn't appear to expo= se any way of knowing the value of a php.ini directive if that value is interpreted as a numeric/long value (parsed via `OnUpdateLong` and `OnUpdateLongGEZero`, see main/main.c). It will return the string value whi= ch was configured and (such as `14m`) but not the internal value parsed from it (such as `14680064`). While I started porting `zend_atol` into WordPress to better interpret valu= es such as `14MB` (14680064) or `0x5teak_and_egg` (5368709120) or `03136k` (1669120) I realized that it's not fully possible to do this, specifically = when the configured value would overflow when computing the byte-size suffix, su= ch as for `9223372036854775807g`, which I believe will have a different result= on different platforms. Noticing a few issues surrounding `post_max_size` and friends, I suggest introducing a new function which takes as its input a numeric string as wou= ld be given in `ini_set( 'post_max_size', ... )` and returns the value that PHP internally parses if it were set with that. Applications could then read the configured value with certainty and wouldn= 't have to duplicate and maintain the internal C code from `php-src` as user-s= pace PHP. ``` $post_max_size =3D ini_get( 'post_max_size' ); $post_max_size_bytes =3D ini_numeric_value( $post_max_size ); ``` Posting here as my first message, thanks for your patience with my unfamiliarity of the process and format. Would like to know your thoughts on the new function and any ideas for a proper name as I don't particularly fe= el like I have found a good one yet. Recap of why this exists: =C2=A0- Applications cannot currently know the configured value of `post_ma= x_size` =C2=A0- If an application wants to approximate that value it needs to repli= cate =C2=A0 =C2=A0internal C code from `php-src` but this will breakdown in extreme-but-allowed cases. =C2=A0- Knowing the configured values is important for communicating releva= nt and =C2=A0 =C2=A0related configuration settings to users and for internal logic= . e.g. Show a user how large of a file they can upload before uploading it and prevent th= em in JavaScript from doing that. =C2=A0- Of several approaches considered this was the simplest way I could = find to =C2=A0 =C2=A0add functionality without implying much bigger changes. Comple= xity inherent to working with these values is left in application code, but by exposing t= he parsed "byte size," those applications can accommodate without having diffe= rent interpretations of the actual configured values. Proposed in https://github.com/php/php-src/pull/8454 Related PR in WordPress, replicating the `zend_atol()` logic in user-space https://github.com/WordPress/wordpress-develop/pull/2660 Thanks for the feedback! Dennis Snell dennis.snell@automattic.com --=_72CE8775-537C-4664-A833-AEDDE7BF79E0--