Framework: Testing\FileFactory::generateImage() causes segmentation fault.

Created on 9 Mar 2017  路  5Comments  路  Source: laravel/framework

  • Laravel Version: 5.4.15
  • PHP Version: 7.0.11

Description:

Here is two things to consider:

  1. A file generated with tmpfile() is deleted automatically when the resource is closed, according to PHP docs:

The file is automatically removed when closed (for example, by calling fclose(), or when there are no remaining references to the file handle returned by tmpfile()), or when the script ends.

  1. Function imagepng($image, $to, ...) closes the resource automatically when $to is a resource, according to PHP docs:

The path or an open stream resource (which is automatically being closed after this function returns) to save the file to. If not set or NULL, the raw image stream will be outputted directly.

When you try to do something like this:

UploadedFile::fake()->image('avatar.jpg');

phpunit just stop with an error segmentation fault, I think is because the resource is closed by imagepng() causing the temporary file beign deleted, as soon as generateImage(...) attempts to return the closed resource it fails.

Here is the FileFactory::generateImage() function for reference:

protected function generateImage($width, $height)
{
    return tap(tmpfile(), function ($temp) use ($width, $height) {
        imagepng(imagecreatetruecolor($width, $height), $temp);
    });
}

I'm not sure if this behavior occurs only on my system (macOS running Laravel Valet), but I'm pretty sure that it only fails when calling imagepng() because the resource ($temp) is closed right after.

Most helpful comment

I will open the PR in the next few hours. 馃暫馃徑

All 5 comments

If this is confirmed as a bug I can make the fix and a pull request.

@sahibalejandro yes please open a PR.

I have the same error while trying to test file upload using Storage::fake() will be happy of a PR can be opened for this.

I will open the PR in the next few hours. 馃暫馃徑

A similar thing happens in Windows 8.1. When I try to do UploadedFile::fake()->image('avatar.jpg'), phpunit crashes.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

RomainSauvaire picture RomainSauvaire  路  3Comments

felixsanz picture felixsanz  路  3Comments

jackmu95 picture jackmu95  路  3Comments

gabriellimo picture gabriellimo  路  3Comments

CupOfTea696 picture CupOfTea696  路  3Comments