Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:121025 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 61504 invoked from network); 9 Sep 2023 04:18:25 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 9 Sep 2023 04:18:25 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id BD3D1180083 for ; Fri, 8 Sep 2023 21:18:24 -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.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM,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-qt1-f171.google.com (mail-qt1-f171.google.com [209.85.160.171]) (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 21:18:24 -0700 (PDT) Received: by mail-qt1-f171.google.com with SMTP id d75a77b69052e-4136bfb3220so17505831cf.1 for ; Fri, 08 Sep 2023 21:18:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1694233103; x=1694837903; darn=lists.php.net; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=9PwGf3IpzFf80ff1IwAKj7C5TOda7V/ME/WKbjR/afU=; b=isksI7s0VhfEw/DVcvqIamwH6+o8OgmjSHPVy3jhChlmbGJW3uM3lSwtzDY9OwyaCs VknCU8SF9IpIUs4awm6tXuAZ071wwpvAdsBCXiAp/9DTCwqotjyjm5spmdML+UaewOMY NQfWoZFBJyYwKD17v1rcrc6DTbjMX+qwjdnQaEQIDqfm3od4LJO6lwhN9D8IRHFAIxgB DNcEh/UOWBypIqmeOHaE+OXpZDoWyBf7SbDcmTxa9kV5YJQf4NZE8afcHsnMFh3pjB8P Ql8IL3WroCf8Dzv87hB7CwnzxeHvRyiQawKYI+zdV/QgoxAjBAwsjHAydN4VW87Nr+eX o4Hw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694233103; x=1694837903; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=9PwGf3IpzFf80ff1IwAKj7C5TOda7V/ME/WKbjR/afU=; b=gVmrO5hEX2VrIe1CSAcyVqwMnPieoiaEXZaoC6/gctNmHiAdvCOEc/qhjm8gVd/OBL gtBbXevD5mkproFK8eRQJTaxu6gYigt6ShBMXrczhrRB4uWcBSABOE83Quzda9NO14bC dwtuqXX/rEqHbDi8MTRLXLZudww3ZLSval2krZrvl7LnVwax3+yFB1z5FKo86LaZ6f4p h1uGXPZvy3ouu84IoZ8gMNiVRz7wLT+BAOoHFLwNu4C9csoNwJB/TEYxBPJ4EInY7LV9 QuJg5hwZJsLQhuLR29kjwNe44w05DYnt8XQ50cJd0j1jR2O+e12KnkSl4cnq/dGrpOqw N09A== X-Gm-Message-State: AOJu0Yz8Y6EMn8HV3bE5RMf/vtTGUfOL1g0+YtYdSqBL+1mchOXXjlNF cZbPHD4JcFzPDN5jWBs/ipzXhMGTF33Jr+/rLUcmyStr X-Google-Smtp-Source: AGHT+IFBiflNvge+AM9Wa3ADbbHH1YhOt1UZbonj6NOwsXm9uj9zHsYS8++yqdxFBh3QeaPkG5fg59kO5AlfHWCH2+A= X-Received: by 2002:ac8:5c09:0:b0:410:165:9e5b with SMTP id i9-20020ac85c09000000b0041001659e5bmr4307969qti.65.1694233103239; Fri, 08 Sep 2023 21:18:23 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Date: Sat, 9 Sep 2023 01:18:12 -0300 Message-ID: To: bishop@php.net Cc: PHP internals Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Subject: Re: [PHP-DEV] FFI in PHAR files From: carlosv775@gmail.com (Vinicius Dias) Ah, that makes total sense. I was worried I was doing something very wrong.= haha Thank you very much for the detailed clarification. This doesn't seem to be a "critical" feature, but I wonder if the documentation shouldn't mention something about only "regular files" being supported. Vinicius Dias, Zend Certified Engineer, iMasters PHP Certified Professional Vinicius Dias, Zend Certified Engineer, iMasters PHP Certified Professional Em sex., 8 de set. de 2023 =C3=A0s 16:55, Bishop Bettini e= screveu: > > 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! T= he short answer is no, FFI does not support loading dynamic libraries conta= ined within a PHAR archive. > > The longer answer is that FFI was not written to be able to support VFS l= ocations, including the phar:// scheme. In this case, PHP starts and invoke= s the code. The code invokes FFI[1] with a phar:// path, which then tries t= o perform a dlopen()[2], which fails because dlopen has no idea how to reso= lve 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 re= solve a path, which would handle the phar:// scheme and other schemes. But,= I would be worried about potential other downstream impacts - esp. securit= y implications - as this is a novel (to me at least) scenario. > > bishop > > [1]:https://github.com/php/php-src/blob/50ca24251d97dbf78b0c1165dac7c1a19= ff1c87a/ext/ffi/ffi.c#L2968C3-L2968C3 > [2]:https://github.com/php/php-src/blob/50ca24251d97dbf78b0c1165dac7c1a19= ff1c87a/Zend/zend_portability.h#L156 > [3]:https://man7.org/linux/man-pages/man3/dlopen.3.html >