phpDocumentor icon indicating copy to clipboard operation
phpDocumentor copied to clipboard

Phar is modified on a run

Open jaapio opened this issue 1 year ago • 22 comments

          I'm still getting an error with phive on Docker:
Notice: require(): zlib: data error in /tools/.phive/phars/phpdocumentor-3.4.1.phar on line 11

Warning: require(phar://phpdocumentor.phar/bin/phpdoc): Failed to open stream: phar error: internal corruption of phar "/tools/.phive/phars/phpdocumentor-3.4.1.phar" (actual filesize mismatch on file "bin/phpdoc") in /tools/.phive/phars/phpdocumentor-3.4.1.phar on line 11

Fatal error: Uncaught Error: Failed opening required 'phar://phpdocumentor.phar/bin/phpdoc' (include_path='.:/usr/local/lib/php') in /tools/.phive/phars/phpdocumentor-3.4.1.phar:11
Stack trace:
#0 {main}
  thrown in /tools/.phive/phars/phpdocumentor-3.4.1.phar on line 11
image

Interestingly, phpDocumentor works when image is being built, but not when I run it on the built image. Perhaps a docker issue.

Originally posted by @jakzal in https://github.com/phpDocumentor/phpDocumentor/issues/3562#issuecomment-1709886494

jaapio avatar Sep 22 '23 11:09 jaapio

Copied from #3562. The phar works fine the first time it’s run but gets corrupted.

I can reproduce the problem now.

  1. Start a PHP Docker container

    docker run -it --rm jakzal/phpqa:alpine sh
    
  2. Install phpDocumentor with phar

    phive --no-progress --home /tools/.phive install \
        --trust-gpg-keys 8AC0BAA79732DD42 phpDocumentor \
        -t /tools/.phive/tmp/f474e60df5620536af2224cbc21a1668 \
        && mv /tools/.phive/tmp/f474e60df5620536af2224cbc21a1668/* /tools/phpDocumentor
    
  3. Run phpDocumentor (works fine)

    /tools/phpDocumentor
    
  4. Run phpDocumentor again (phar is now corrupted)

    /tools/phpDocumentor
    

Other phar files on the image do not get corrupted.

image

jakzal avatar Sep 22 '23 12:09 jakzal

I'm trying to reproduce this issue with the steps you provide... but it does download php 3.3.1 for me? Do I need to update something before phive will pull the correct version?

jaapio avatar Sep 22 '23 12:09 jaapio

Strange. As you see on my screenshot it downloaded 3.4.1 for me.

Have you tried @dharmann's steps instead? https://github.com/phpDocumentor/phpDocumentor/issues/3562#issuecomment-1731218311

This should definitely download v3.4.1:

wget https://github.com/phpDocumentor/phpDocumentor/releases/download/v3.4.1/phpDocumentor.phar
chmod +x phpDocumentor.phar
./phpDocumentor.phar --version

The same issue persists.

jakzal avatar Sep 22 '23 12:09 jakzal

ok, I got a way to reproduce this, it seems to be related to the php setting phar.readonly when you execute:

php -d phar.readonly=off ./phpdocumentor.phar it will keep working.

Neverless it should not be modified after execution. I will continue the research on this.

jaapio avatar Sep 22 '23 12:09 jaapio

Confirmed phar.readonly=on makes it continues to work after the first run 👍 great find!

jakzal avatar Sep 22 '23 12:09 jakzal

Hm... this is gonna be a though search... I cannot extract the corrupted phar, So I have no clue on what has been changed

jaapio avatar Sep 22 '23 12:09 jaapio

Hm... this is gonna be a though search... I cannot extract the corrupted phar, So I have no clue on what has been changed

Sorry, maybe I don't really understand your sentence, because a phar can be extract simply using $ phar extract -f </PATH/OF/FILE.PHAR>

dharmann avatar Sep 22 '23 12:09 dharmann

Ah I was not aware of the existence of phar, I do always use php for this

jaapio avatar Sep 22 '23 12:09 jaapio

Ah I was not aware of the existence of phar, I do always use php for this

In a Debian like Linux distro you can find it in /usr/bin/phar, and in windows I think it could be phar.pharbat or pharcommand.phar

dharmann avatar Sep 22 '23 12:09 dharmann

phpDocumentor.zip

Can you confirm this phar keeps working? It's not zipped like the released phar. It's a zip file because github does not allow me to upload phar files in issues.

jaapio avatar Sep 22 '23 12:09 jaapio

phpDocumentor.zip

Can you confirm this phar keeps working? It's not zipped like the released phar. It's a zip file because github does not allow me to upload phar files in issues.

It worked like a charm! Every time (three) that I ran it!

dharmann avatar Sep 22 '23 13:09 dharmann

The only difference between this phar, and another one I created on the same code base version was the Boxphp setting compression, in the release this was set to GZ. to compress the release and make it a smaller download.

The version you tested was not compressed.

jaapio avatar Sep 22 '23 13:09 jaapio

https://github.com/phpDocumentor/phpDocumentor/commit/d85524df238467baae619b02b7435b0797fc4a51

This seems to be the cause of the issue, I will try to do a new release soon, but I have to wrap things up. As I made some significant changes since the last release.

jaapio avatar Sep 22 '23 13:09 jaapio

d85524d

This seems to be the cause of the issue, I will try to do a new release soon, but I have to wrap things up. As I made some significant changes since the last release.

Good job! Thank you very much!

dharmann avatar Sep 22 '23 13:09 dharmann

I am getting the same issue by downloading it from the web with v3.4.0 and v3.4.1

Cartman34 avatar Sep 29 '23 08:09 Cartman34

I just released v3.4.2, this should fix this issue. Please let me know when you face any issues with the new release.

jaapio avatar Oct 03 '23 20:10 jaapio

I just released v3.4.2, this should fix this issue. Please let me know when you face any issues with the new release.

Sadly I got the exactly same error: $ ./phpDocumentor.phar version

PHP Notice: require(): zlib: data error in /tmp/phpDocumentor.phar on line 11 PHP Warning: require(phar://phpdocumentor.phar/bin/phpdoc): Failed to open stream: phar error: internal corruption of phar "/tmp/phpDocumentor.phar" (actual filesize mismatch on file "bin/phpdoc") in /tmp/phpDocumentor.phar on line 11 PHP Fatal error: Uncaught Error: Failed opening required 'phar://phpdocumentor.phar/bin/phpdoc' (include_path='.:/usr/share/php') in /tmp/phpDocumentor.phar:11 Stack trace: #0 {main}      thrown in /tmp/phpDocumentor.phar on line 11

Here the checksum of the phar before and after it's usage: $ md5sum phpDocumentor.phar*

948baaac402ad96ba519398a45dd49e1 phpDocumentor.phar.original 230d6188965737cd98764c32f50858a7 phpDocumentor.phar

dharmann avatar Oct 04 '23 08:10 dharmann

The latest version works for me 👍

jakzal avatar Oct 04 '23 10:10 jakzal

@dharmann can you provide the values of the phar settings in your ini file with me?

jaapio avatar Oct 04 '23 18:10 jaapio

@dharmann can you provide the values of the phar settings in your ini file with me?

For sure! I'm using PHP 8.1.2 and following is the "phar part" of phpinfo() output on CLI:

Phar

Phar: PHP Archive support => enabled Phar API version => 1.1.1 Phar-based phar archives => enabled Tar-based phar archives => enabled ZIP-based phar archives => enabled gzip compression => enabled bzip2 compression => disabled (install ext/bz2) Native OpenSSL support => enabled

Phar based on pear/PHP_Archive, original concept by Davey Shafik. Phar fully realized by Gregory Beaver and Marcus Boerger. Portions of tar implementation Copyright (c) 2003-2009 Tim Kientzle. Directive => Local Value => Master Value phar.cache_list => no value => no value phar.readonly => Off => Off phar.require_hash => On => On

Is it enough?

dharmann avatar Oct 05 '23 08:10 dharmann

I've updated to 3.4.3 and the problem seems to persist. ;-(

dharmann avatar Dec 28 '23 11:12 dharmann

I've updated to 3.4.3 and the problem seems to persist. ;-(

I'm sharing in attachment the content of the phar BEFORE and AFTER the first run. Due to a limitation of github, I can't attach the whole zipped file (27MB), but a link to download it

Please, let me know if it's ok.

Thank you!

dharmann avatar Dec 28 '23 12:12 dharmann