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

Managed to reproduce this issue. Was uploading an image with jquery.dm-uploader.min.js, and trying to do some image manipulation, but when I got this error: #3174

Closed
pixobit opened this issue Jun 26, 2020 · 11 comments

Comments

@pixobit
Copy link
Contributor

pixobit commented Jun 26, 2020

Managed to reproduce this issue. Was uploading an image with jquery.dm-uploader.min.js, and trying to do some image manipulation, but when I got this error:
{title: "ErrorException", type: "ErrorException", code: 500, message: "getimagesize(): Read error!",…} code: 500 file: "C:\xampp\htdocs\project\app\Controllers\File.php" line: 85 message: "getimagesize(): Read error!" title: "ErrorException" trace: [{function: "errorHandler", class: "CodeIgniter\Debug\Exceptions", type: "->",…},…] type: "ErrorException"

Then I was basically getting the same response as the OP.

Note: I managed to get the real exception by printing in in the FormatException.php file

Originally posted by @pixobit in #1274 (comment)

@pixobit
Copy link
Contributor Author

pixobit commented Jun 26, 2020

To be even more exact, I was getting this exception from trying to save a png file: imagepng($image, $imagePath, $quality).
Turns out the 3rd parameter doesn't work, so if I remove it, it's working fine.

Or maybe it was happening from passing accidentally an image resource to getImageSize instead of a path... Not sure which one caused that exception from the post, as I was trying a few things, but definitely one of these two.

Using PHP Version 7.4.4

@paulbalandan
Copy link
Member

Can you give a simple test script to replicate the problem?

@pixobit
Copy link
Contributor Author

pixobit commented Jul 19, 2020

No, this was too long time ago for that, but I believe I gave enough information to reproduce it, and I'm not even sure if it was fixed or no in 4.0.4

@crustamet
Copy link
Contributor

I think this should be closed, because i had no problems uploading and manipulating the image.

I had some problems with max_file_size for the validation rules, but they got fixed.
Maybe that was the problem here also

@pixobit
Copy link
Contributor Author

pixobit commented Aug 27, 2020

I think this should be closed, because i had no problems uploading and manipulating the image.

I had some problems with max_file_size for the validation rules, but they got fixed.
Maybe that was the problem here also

You're completely missing the point. The issue of this case was doing something that should throw an exception, but the exception thrown was wrong, and had to actually get it by checking before FormatException.php...

Therefore to reproduce it, you have to be unsuccessful to manipulate the image, as you need it to throw an error in the first place. But I will check if it still happens, and try to fix it, then do a pull request.

@paulbalandan
Copy link
Member

If you can throw in the code from your App\Controllers\File class then that would be a great help, instead of having us hanging. It is pretty hard to decipher what is happening on line 85 that caused this exception and analyzing the related code from the stack trace. If you have sensitive information in that class, you can mask those with asterisks.

@derektconsulting
Copy link

derektconsulting commented Aug 28, 2020

Here is the code from my controller method:
public function iptcFail()
{
$image = \Config\Services::image()
->withFile('***/_DSC_0047_34657.jpg')
->getEXIF();

	dd($image);
}

Returns: exif_read_data(_DSC_0047_34657.jpg): Incorrect APP1 Exif Identifier Code

Note this does not return an error on every image, only certain ones, and I haven't figured out what it is about the image...maybe it's a bad Exif identifier code =)

If I can help by providing the _DSC_0047_34657.jpg image I used, just let me know how I can get it to you.

Hope that helps

@pixobit
Copy link
Contributor Author

pixobit commented Aug 29, 2020

Alright, found the actual problem, and it's on JSONFormatter.php ln.67
$result = json_encode($data, $options, 512);

So in my latest case this json_encode was returning a JSON_ERROR_UNSUPPORTED_TYPE error, which caused it to enter this part:
throw FormatException::forInvalidJSON(json_last_error_msg());
which at the end of the day will throw you an error that's about the json_encoding, and has nothing to do with the actual exception.

I can't post the full original error message, as it would be huge, but that's pretty much straight to the point

@paulbalandan
Copy link
Member

Here is the code from my controller method:
public function iptcFail()
{
$image = \Config\Services::image()
->withFile('***/_DSC_0047_34657.jpg')
->getEXIF();

	dd($image);
}

Returns: exif_read_data(_DSC_0047_34657.jpg): Incorrect APP1 Exif Identifier Code

Note this does not return an error on every image, only certain ones, and I haven't figured out what it is about the image...maybe it's a bad Exif identifier code =)

If I can help by providing the _DSC_0047_34657.jpg image I used, just let me know how I can get it to you.

Hope that helps

@derektconsulting is your issue related to this one? This issue is on exception thrown on formatting, while yours is related to exception on exif. You should open a separate ticket for that.

Short answer, exif only works on JPEG and TIFF files. It will likely fail on incompatible image types OR images with malformed headers. You should scrutinize that image.

@paulbalandan
Copy link
Member

@pixobit since you are not giving any code that will truly help in reproducing the errors you encountered, I tried making one myself:

        // App\Controllers\Home

        public function index()
	{
		// return view('welcome_message');

		$data = fopen('php://output', 'w');

		$result = json_encode($data, JSON_PRETTY_PRINT, 512);

                // error here is JSON_ERROR_UNSUPPORTED_TYPE
                // since a resource is not allowed for encoding
		if (JSON_ERROR_NONE !== json_last_error())
		{
			throw FormatException::forInvalidJSON(json_last_error_msg());
		}

		var_dump($result);
	}

The exception is pretty much expected.

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

No branches or pull requests

4 participants