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

fixed possible endless loop processing png file with wrong filesize #266

Merged
merged 1 commit into from
Apr 16, 2021

Conversation

edanp
Copy link

@edanp edanp commented Sep 9, 2020

I'm processing a list of files that I read from an external url and saving them with the same filename on disk (temp name only for processing). Since the library is using filesize which is cached, the png parser goes into an endless loop when dealing with a smaller file than the previous one.

I have few options to solve it outside the library like using a different name per file or calling clearstatcache before every call to the library, but I still think it should not be possible to reach an endless loop in the code.

Below is an example code that should trigger the endless loop. big-file.png should be bigger in size than small-file.png.

My fix checks that fread returns data and breaks with a warning if it returns empty.

<?php
        $target = '/tmp/tmp.png';

        // don't use PHP copy because it will clear cache
        $src = '/tmp/big-file.png';
        exec("cp $src $target");
        $getID3 = new \getID3;
        $analyze = $getID3->analyze($target);

        $src = '/tmp/small-file.png';
        exec("cp $src $target");
        $getID3 = new \getID3;
        $analyze = $getID3->analyze($target);

@JamesHeinrich JamesHeinrich merged commit 422485c into JamesHeinrich:master Apr 16, 2021
@JamesHeinrich
Copy link
Owner

Sorry, somehow I didn't notice this PR until just now.

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

Successfully merging this pull request may close these issues.

None yet

2 participants