Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Phar is modified on a run #3582

Open
jaapio opened this issue Sep 22, 2023 · 22 comments
Open

Phar is modified on a run #3582

jaapio opened this issue Sep 22, 2023 · 22 comments

Comments

@jaapio
Copy link
Member

jaapio commented Sep 22, 2023

          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 #3562 (comment)

@phpdoc-bot phpdoc-bot added this to Needs triage in phpDoc issue triage board Sep 22, 2023
@jakzal
Copy link

jakzal commented Sep 22, 2023

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

@jaapio
Copy link
Member Author

jaapio commented Sep 22, 2023

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?

@jakzal
Copy link

jakzal commented Sep 22, 2023

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

Have you tried @dharmann's steps instead? #3562 (comment)

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.

@jaapio
Copy link
Member Author

jaapio commented Sep 22, 2023

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.

@jakzal
Copy link

jakzal commented Sep 22, 2023

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

@jaapio
Copy link
Member Author

jaapio commented Sep 22, 2023

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

@dharmann
Copy link

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>

@jaapio
Copy link
Member Author

jaapio commented Sep 22, 2023

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

@jaapio jaapio moved this from Needs triage to High priority in phpDoc issue triage board Sep 22, 2023
@dharmann
Copy link

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

@jaapio
Copy link
Member Author

jaapio commented Sep 22, 2023

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.

@dharmann
Copy link

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!

@jaapio
Copy link
Member Author

jaapio commented Sep 22, 2023

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
Copy link
Member Author

jaapio commented Sep 22, 2023

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.

@dharmann
Copy link

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!

@Cartman34
Copy link

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

@jaapio
Copy link
Member Author

jaapio commented Oct 3, 2023

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 jaapio closed this as completed Oct 3, 2023
phpDoc issue triage board automation moved this from High priority to Closed Oct 3, 2023
@dharmann
Copy link

dharmann commented Oct 4, 2023

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

@jaapio jaapio reopened this Oct 4, 2023
phpDoc issue triage board automation moved this from Closed to Needs triage Oct 4, 2023
@jakzal
Copy link

jakzal commented Oct 4, 2023

The latest version works for me 👍

@jaapio
Copy link
Member Author

jaapio commented Oct 4, 2023

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

@dharmann
Copy link

dharmann commented Oct 5, 2023

@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
Copy link

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

@dharmann
Copy link

dharmann commented Dec 28, 2023

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
phpDoc issue triage board
  
Needs triage
Development

No branches or pull requests

4 participants