Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:121020 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 95725 invoked from network); 8 Sep 2023 19:55:12 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 8 Sep 2023 19:55:12 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id B796D1804C6 for ; Fri, 8 Sep 2023 12:55:11 -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=-1.4 required=5.0 tests=BAYES_00, FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS, HTML_MESSAGE,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-yb1-f174.google.com (mail-yb1-f174.google.com [209.85.219.174]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature ECDSA (P-256) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Fri, 8 Sep 2023 12:55:11 -0700 (PDT) Received: by mail-yb1-f174.google.com with SMTP id 3f1490d57ef6-d7e9d849bdfso2179497276.3 for ; Fri, 08 Sep 2023 12:55:11 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694202910; x=1694807710; h=cc:to:subject:message-id:date:from:reply-to:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=qEOM7KQJ7aAgp5YRgqmIDvNVqy/efGVz23Otp+wQQqU=; b=EJtK33p2XH1jpucKhrNAuFmfbhTFMNQ2v/VKOEVQowEBovBHMMBzE7AHEi4PBL0U8B a7rD8tt7ZE39N4SWfNRs7s35Kx8DpxH67gdtt0jTl+CuP+gLQD/7Hxf4QhxhsetbvdeO Pr42UAQBra9F4iOi4Md1piUgbYdVOXjDQzpdUMPJDZBTfFjCXCMGKsGKyJ93I1CpNm6e Bl0b13O82PoPeN4PhTs8QpFsfSmcpBpZEPPOHMgz1iF9hv8d3qhoB9artlrRodK+R5GQ Mx5tVCXcLsK0uhMS1q1o+xQv1FyIC99r/g3nOlzH3VS25PDA083O8W3wUprmzaBR97hb QXXA== X-Gm-Message-State: AOJu0YxDucut0aoUgr/Op6GzDzcKHIAp+bxFYvCuQg9y9ZSIgUF1ytjD P0HHBqw6mXNxyIbvez0RErY5SnbRB9m9Rgy0NPg= X-Google-Smtp-Source: AGHT+IHbuLy+wUU1O00Ct3CY6sYBoNyLzEgd5L0ESNQghJXrJonZFWj45zaKG8Mcumrn7zDIsE+2RnfXZ8OUjXRV2eg= X-Received: by 2002:a25:ad04:0:b0:d54:b34c:1c7b with SMTP id y4-20020a25ad04000000b00d54b34c1c7bmr2993579ybi.59.1694202910316; Fri, 08 Sep 2023 12:55:10 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Reply-To: bishop@php.net Date: Fri, 8 Sep 2023 15:54:34 -0400 Message-ID: To: Vinicius Dias Cc: PHP internals Content-Type: multipart/alternative; boundary="000000000000a59ca40604de5ac2" Subject: Re: [PHP-DEV] FFI in PHAR files From: bishop@php.net (Bishop Bettini) --000000000000a59ca40604de5ac2 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Fri, Sep 8, 2023 at 2:33=E2=80=AFPM Vinicius Dias = wrote: > I was playing around with some libraries using FFI and I wanted to > share a .phar with the result, but to my surprise, it didn't work. > > Apparently we are not able to load shared libraries using FFI from > within .phar files. > Is that the expected behavior or is it a bug in the FFI extension? > > I have setup a dummy repo so the error could be easily reproduced: > https://github.com/CViniciusSDias/ffi-phar-problem > > I am sorry if this is not the list to send this type of problem. I > will gladly move the thread to the right one if someone points it out. > https://www.php.net/unsub.php Erstwhile PHAR extension maintainer here. What an interesting question! The short answer is no, FFI does not support loading dynamic libraries contained within a PHAR archive. The longer answer is that FFI was not written to be able to support VFS locations, including the phar:// scheme. In this case, PHP starts and invokes the code. The code invokes FFI[1] with a phar:// path, which then tries to perform a dlopen()[2], which fails because dlopen has no idea how to resolve PHAR paths: dlopen() expects a path that the OS can resolve[3]. I suppose it'd be possible to improve FFI to call the PHP VFS layer to resolve a path, which would handle the phar:// scheme and other schemes. But, I would be worried about potential other downstream impacts - esp. security implications - as this is a novel (to me at least) scenario. bishop [1]: https://github.com/php/php-src/blob/50ca24251d97dbf78b0c1165dac7c1a19ff1c87= a/ext/ffi/ffi.c#L2968C3-L2968C3 [2]: https://github.com/php/php-src/blob/50ca24251d97dbf78b0c1165dac7c1a19ff1c87= a/Zend/zend_portability.h#L156 [3]:https://man7.org/linux/man-pages/man3/dlopen.3.html --000000000000a59ca40604de5ac2--