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

Not documented. getimagesize() fatal error when invalid filename #3714

Open
kitrio opened this issue Sep 5, 2024 · 1 comment
Open

Not documented. getimagesize() fatal error when invalid filename #3714

kitrio opened this issue Sep 5, 2024 · 1 comment

Comments

@kitrio
Copy link

kitrio commented Sep 5, 2024

https://www.php.net/getimagesize

According to the "Caution" in the document: The return value succeeds even if the arguments are invalid.

But PHP 8 is different.

$result = getimagesize('');
var_dump($result); 

php 7.4

Warning: getimagesize(): Filename cannot be empty in /home/user/scripts/code.php on line 4
bool(false)

PHP 8.0 or higher

Fatal error: Uncaught ValueError: Path cannot be empty in /home/user/scripts/code.php:4
Stack trace:
#0 /home/user/scripts/code.php(4): getimagesize('')
#1 {main}
thrown in /home/user/scripts/code.php on line 4

and some GD extension's function is also

@cmb69
Copy link
Member

cmb69 commented Sep 5, 2024

You are right about the warning/ValueError, but that is not specific to getimagesize() but rather happens when opening a stream:

https://github.com/php/php-src/blob/6732b8892dcdb3928b69ba6351161759355d79ae/main/streams/streams.c#L2196-L2199

As such it would need to be documented for other respective functions (such as fopen() and likely many others) as well. I'm not sure that it is a good idea to document this for each affected function.

According to the "Caution" in the document: The return value succeeds even if the arguments are invalid.

That's not what the English documentation states (maybe you're reading a translation). That remark is about invalid image files; getimagesize() doesn't validate the whole image file, but rather reads the first bytes to see whether it might be a supported image type, and then only reads as much information from the file as necessary to fill in the information which is returned by getimagesize(). So you should not use this function to verify that an arbitrary file contains a valid image.

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

2 participants